-
-
Notifications
You must be signed in to change notification settings - Fork 108
fix: UnsafeAccessor for generic base class properties with type parameter types #4452
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
…eter types (#4431) When a property in a generic base class has a type that is the type parameter itself (e.g., `T Provider { get; }` in `GenericBase<T>`), the UnsafeAccessor return type needs to be the type parameter name `T`, not the concrete type substitution. Changes: - Add `PropertyTypeAsTypeParameter` field to `PropertyDataSourceModel` to track when a property type is a type parameter - Detect type parameters in `ExtractPropertyModel` by checking the original property definition type - Use the type parameter name in UnsafeAccessor generation for generic types - Fix TestMetadataGenerator to use closed generic type for backing field lookup This enables AOT-compatible property injection for patterns like: ```csharp public abstract class GenericBase<T> where T : class { [ClassDataSource] public T Provider { get; init; } } public class ConcreteTest : GenericBase<MyProvider> { } ``` Fixes #4431 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryThis PR fixes Critical IssuesNone found ✅ The PR correctly addresses the issue by:
The fix in TestMetadataGenerator.cs correctly uses SuggestionsNone - the implementation is well-designed and handles the nuances of generic types correctly. Verdict✅ APPROVE - No critical issues. The PR properly implements dual-mode support, maintains AOT compatibility, and follows all TUnit critical rules. |
Summary
MissingFieldExceptionwhen using[ClassDataSource]on properties in generic base classes where the property type is the type parameter itself (e.g.,public T Provider { get; init; })Problem
When using patterns like:
The generated UnsafeAccessor was incorrectly using the concrete type substitution (
MyProvider) as the return type instead of the type parameter name (T), causing aMissingFieldExceptionat runtime.Solution
PropertyTypeAsTypeParameterfield to track when a property type is a type parameter in the original definitionT) instead of the concrete type when the property type is a type parameterTestMetadataGeneratorto use the closed generic type for backing field lookupTest plan
CompositionPatternTests.cswith comprehensive test cases for the generic base class patternFixes #4431
🤖 Generated with Claude Code