-
-
Couldn't load subscription status.
- Fork 94
Fix generic implicit operators compilation error in AotConverterGenerator #2758
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
Conversation
…valid AotConverter code Co-authored-by: thomhurst <[email protected]>
…n AotConverterGenerator Co-authored-by: thomhurst <[email protected]>
…oduction Co-authored-by: thomhurst <[email protected]>
|
@copilot Will this still generate a runnable test? |
|
@claude review this |
|
Claude finished @thomhurst's task —— View job Code ReviewTasks:
Review Summary ✅This is a well-implemented fix that correctly addresses the compilation error described in issue #2757. AnalysisThe Problem: public Type SourceType => typeof(T); // CS0246: 'T' could not be found
return (global::Foo<>)typedValue; // CS7003: Unexpected use of unbound generic nameThe Solution: // Skip conversion operators with unbound generic type parameters
// These cannot be properly represented in AOT converters at runtime
if (sourceType.IsGenericDefinition() || targetType.IsGenericDefinition())
{
return null;
}Code Quality Assessment✅ Strengths:
✅ Security & Best Practices:
Answering Your Question: "Will this still generate a runnable test?"Yes, tests will still be runnable. Here's why:
Minor SuggestionsConsider for future enhancement (not blocking for this PR):
Verdict: APPROVED ✅This fix correctly solves the compilation issue while maintaining test functionality. The implementation is clean, well-documented, and follows established patterns in the codebase. |
Yes, this will still generate a runnable test. The fix only prevents generation of invalid AOT converters for generic operators with unbound type parameters, but TUnit has robust fallback mechanisms in CastHelper.cs that handle type conversion at runtime. When an AOT converter isn't available, the framework falls back to reflection-based conversion using The fix is surgical and preserves all functionality while preventing the compilation errors from invalid generated code. |
The
AotConverterGeneratorwas attempting to generate AOT converters for generic implicit/explicit operators with unbound type parameters, which resulted in invalid C# code generation and compilation errors.Problem
When using generic types with implicit operators like:
The source generator would produce invalid code in
AotConverters.g.cs:Solution
Added a check in the
GetConversionInfomethod to skip conversion operators where either the source type or target type contains unbound type parameters. Generic operators with type parameters cannot be properly represented in AOT converters at runtime since the concrete types are not known at compile time.The fix uses the existing
IsGenericDefinition()extension method to detect types with unbound type parameters:This preserves functionality for concrete type conversions while preventing the generation of invalid code for generic operators.
Fixes #2757.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.