Skip to content

Add MSGH008 return type validation for MethodBodyGenerator#92

Merged
dex3r merged 1 commit intofeature/metehod_templatefrom
copilot/write-code-to-make-wrongreturntype-tests-pass
Mar 25, 2026
Merged

Add MSGH008 return type validation for MethodBodyGenerator#92
dex3r merged 1 commit intofeature/metehod_templatefrom
copilot/write-code-to-make-wrongreturntype-tests-pass

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

[MethodBodyGenerator] methods with invalid return types were silently accepted. The defined MSGH008 diagnostic was never reported.

  • Added validation in GeneratesMethodGenerationTargetCollector.Collect() after partial method resolution: generator return type must be either IMethodBodyGenerator (fluent pattern) or match the target partial method's return type (simple pattern)
  • Diagnostic location uses generatorMethod.ReturnType.GetLocation() to highlight exactly the return type token
// Returns object instead of int — now reports MSGH008 on "object"
[MethodBodyGenerator(nameof(JustReturnConstant))]
public static object JustReturnConstantGenerator() =>
    Generate.MethodBody()
        .ForMethod().WithReturnType<int>().WithNoParameters()
        .UseProvidedBody(() => 42);

All 3 WrongReturnType tests now pass. Full suite green with no regressions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Write code to make WrongReturnType tests pass</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix WrongReturnType tests to ensure they pass Add MSGH008 return type validation for MethodBodyGenerator Mar 25, 2026
Copilot AI requested a review from dex3r March 25, 2026 15:06
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
@dex3r dex3r force-pushed the copilot/write-code-to-make-wrongreturntype-tests-pass branch from 0f95181 to c4fdc7b Compare March 25, 2026 15:16
@dex3r dex3r marked this pull request as ready for review March 25, 2026 15:16
Copilot AI review requested due to automatic review settings March 25, 2026 15:16
@dex3r dex3r merged commit 0bce1ab into feature/metehod_template Mar 25, 2026
1 check failed
@dex3r dex3r deleted the copilot/write-code-to-make-wrongreturntype-tests-pass branch March 25, 2026 15:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes missing reporting of the already-defined MSGH008 diagnostic by adding return-type validation for [MethodBodyGenerator] methods during generation target collection, ensuring invalid generator return types are rejected early and highlighted precisely at the return-type syntax.

Changes:

  • Validate generator method return type after resolving the target partial method.
  • Report MSGH008 when the generator return type is neither IMethodBodyGenerator (fluent pattern) nor the target partial method’s return type (simple pattern).
  • Use the generator method’s return type syntax location so the diagnostic highlights only the return type token.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants