Fix unsafe accessor generic type args #2116
Draft
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.
Fix unsafe accessor generic type args
Description
Fixes incorrect UnsafeAccessor code generation when multiple types inherit from different instantiations of the same generic base class.
Problem
When mapping types like:
The
UnsafeAccessorwould generate code with wrong type arguments for the second type, causing:error CS1503: Argument 1: cannot convert from 'A2' to 'A<IB>'Root Cause
UnsafeAccessorTypeContextcaches accessors bysymbol.OriginalDefinition, which ignores type arguments. When processingA1 : A<IB>, it caches the accessor. When processingA2 : A<IC>, it returns the cached accessor withIBtype arguments instead ofIC.Solution
Pass the actual
containingTypeat invocation time toBuildAssignmentandBuildAccessmethods, instead of using the cached symbol's type arguments. This preserves accessor caching (for class generation and naming) while using correct type arguments at each invocation site.Checklist