Skip to content

Commit 0bce1ab

Browse files
Copilotdex3r
andauthored
Add return type validation for MethodBodyGenerator (MSGH008) (#92)
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. Agent-Logs-Url: https://github.com/dex3r/EasySourceGenerators/sessions/8515330e-e7a2-438c-8d6a-d6c01baa8bbc Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
1 parent 4a29f54 commit 0bce1ab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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)