-
-
Notifications
You must be signed in to change notification settings - Fork 86
Fix AotTypeResolver generation for non-generic types like System.Type #2866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot finished work on behalf of
thomhurst
August 11, 2025 15:19
This was referenced Aug 12, 2025
This was referenced Aug 20, 2025
Merged
Closed
This was referenced Sep 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The AotTypeResolver source generator was incorrectly treating non-generic types like
System.Type
as generic type definitions, causing compilation errors when generating AOT-compatible code.Problem
After updating from version 0.25.21 to 0.53.0, users encountered compilation errors like:
This was caused by the generated
AotTypeResolver.g.cs
file containing invalid code:Since
System.Type
is not a generic type, the syntaxSystem.Type<System.Type>
is invalid C# and causes compilation to fail.Root Cause
The issue was in the
ExtractGenericTypeCombinations
method, which was creatingGenericTypeCombination
objects for any type that appeared inMakeGenericType
calls, without validating whether the type was actually a generic type definition.When code like
typeof(List<>).MakeGenericType(typeof(Type))
was analyzed, the generator incorrectly treatedSystem.Type
(which was passed as a type argument) as a generic type definition instead of recognizing thatList<>
was the actual generic type definition.Solution
Added
IsGenericTypeDefinition
helper method that properly validates whether a type is actually a generic type definition usingIsGenericType
andIsUnboundGenericType
checks.Enhanced
ExtractGenericTypeCombinations
to filter out non-generic types before creating combinations:Added defensive validation in
GenerateGenericTypeCombination
to prevent generation of invalid generic type constructions as an additional safety measure.Verification
AotTypeResolver.g.cs
files no longer contain invalid generic type constructionsThe fix is minimal and surgical, specifically targeting the reported issue without affecting other source generation functionality.
Fixes #2865.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.