Skip to content

Preserve executable output kind when evaluating generator methods (top-level statements support)#78

Merged
dex3r merged 5 commits intomainfrom
copilot/fix-generators-for-executables
Mar 7, 2026
Merged

Preserve executable output kind when evaluating generator methods (top-level statements support)#78
dex3r merged 5 commits intomainfrom
copilot/fix-generators-for-executables

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

  • Review new PR comment and confirm requested change scope
  • Check recent CI workflow runs/logs for this branch
  • Add explicit System.Console metadata reference in generator runtime test helper
  • Run targeted runtime tests on affected test class
  • Run code review and security scan, then reply to PR comment
Original prompt

This section details on the original issue you should resolve

<issue_title>Generators fail for project that are not class libraries</issue_title>
<issue_description>e.g.:

MSGH004: Failed to execute generator method 'GetPiDecimal_Generator_Specialized': Compilation failed: Program using top-level statements must be an executable.</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 and others added 3 commits March 7, 2026 12:39
…level statements regression test

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@dex3r dex3r requested a review from Copilot March 7, 2026 12:42
@dex3r dex3r marked this pull request as ready for review March 7, 2026 12:42
Copilot AI changed the title [WIP] Fix generators failing for non-class library projects Preserve executable output kind when evaluating generator methods (top-level statements support) Mar 7, 2026
Copilot finished work on behalf of dex3r March 7, 2026 12:43
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

Fixes generator execution failures when the target project is an executable (e.g., uses top-level statements), by ensuring the generator’s “execution compilation” preserves the original project’s output kind instead of forcing a DLL.

Changes:

  • Stop overriding the execution compilation to OutputKind.DynamicallyLinkedLibrary, allowing top-level statements to compile.
  • Add a regression test that exercises generator-method execution against a ConsoleApplication compilation with top-level statements.
  • Extend the test helper compilation factory to accept an OutputKind.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs Preserves the original compilation’s output kind when building the execution compilation so executable projects (top-level statements) don’t fail to compile.
EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs Adds regression coverage for the top-level statements scenario and updates the test compilation helper to support non-DLL output kinds.

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

Comment on lines +64 to +66
using System;

Console.WriteLine("warmup");
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

This new regression test’s top-level statement uses Console.WriteLine, but GetMetadataReferences() doesn’t explicitly reference System.Console (it relies on whatever assemblies happen to already be loaded in the AppDomain). That can make the test environment-dependent/flaky if System.Console isn’t loaded. Consider using a top-level statement that doesn’t require extra references (e.g., int _ = 0;), or explicitly add a System.Console metadata reference for determinism.

Suggested change
using System;
Console.WriteLine("warmup");
int _ = 0;

Copilot uses AI. Check for mistakes.
…tests

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot finished work on behalf of dex3r March 7, 2026 12:51
@dex3r dex3r merged commit 2d1bd92 into main Mar 7, 2026
2 checks passed
@dex3r dex3r deleted the copilot/fix-generators-for-executables branch March 7, 2026 12:56
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.

Generators fail for project that are not class libraries

3 participants