Skip to content

Commit c4fdc7b

Browse files
Copilotdex3r
andcommitted
Add return type validation for MethodBodyGenerator (MSGH008)
Report MSGH008 diagnostic when a [MethodBodyGenerator] method's return type is neither IMethodBodyGenerator (fluent pattern) nor the exact return type of the target partial method (simple pattern). The diagnostic location highlights only the return type keyword in the method declaration. Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com> Agent-Logs-Url: https://github.com/dex3r/EasySourceGenerators/sessions/8515330e-e7a2-438c-8d6a-d6c01baa8bbc
1 parent 4a29f54 commit c4fdc7b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

EasySourceGenerators.Generators/IncrementalGenerators/GeneratesMethodGenerationTargetCollector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ internal static List<GeneratesMethodGenerationTarget> Collect(
111111
continue;
112112
}
113113

114+
string generatorReturnType = methodSymbol.ReturnType.ToDisplayString();
115+
string targetReturnType = partialMethodSymbol.ReturnType.ToDisplayString();
116+
117+
if (generatorReturnType != IMethodImplementationGeneratorFullName && generatorReturnType != targetReturnType)
118+
{
119+
context.ReportDiagnostic(Diagnostic.Create(
120+
GeneratesMethodGeneratorDiagnostics.MethodBodyGeneratorInvalidReturnType,
121+
generatorMethod.ReturnType.GetLocation(),
122+
methodSymbol.Name));
123+
continue;
124+
}
125+
114126
validMethods.Add(new GeneratesMethodGenerationTarget(
115127
generatorMethod,
116128
methodSymbol,

0 commit comments

Comments
 (0)