From c4fdc7b7800f0fadb6fb050a26457e29e17948af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 15:05:06 +0000 Subject: [PATCH] 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 --- .../GeneratesMethodGenerationTargetCollector.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/EasySourceGenerators.Generators/IncrementalGenerators/GeneratesMethodGenerationTargetCollector.cs b/EasySourceGenerators.Generators/IncrementalGenerators/GeneratesMethodGenerationTargetCollector.cs index 7d69104..bacb1d4 100644 --- a/EasySourceGenerators.Generators/IncrementalGenerators/GeneratesMethodGenerationTargetCollector.cs +++ b/EasySourceGenerators.Generators/IncrementalGenerators/GeneratesMethodGenerationTargetCollector.cs @@ -111,6 +111,18 @@ internal static List Collect( continue; } + string generatorReturnType = methodSymbol.ReturnType.ToDisplayString(); + string targetReturnType = partialMethodSymbol.ReturnType.ToDisplayString(); + + if (generatorReturnType != IMethodImplementationGeneratorFullName && generatorReturnType != targetReturnType) + { + context.ReportDiagnostic(Diagnostic.Create( + GeneratesMethodGeneratorDiagnostics.MethodBodyGeneratorInvalidReturnType, + generatorMethod.ReturnType.GetLocation(), + methodSymbol.Name)); + continue; + } + validMethods.Add(new GeneratesMethodGenerationTarget( generatorMethod, methodSymbol,