Fix accessibility and type-matching for generic extension method lookups#19536
Fix accessibility and type-matching for generic extension method lookups#19536T-Gro merged 17 commits intodotnet:mainfrom
Conversation
❗ Release notes required
|
…d extension lookups (CE, Dispose, etc.)
3f7dd89 to
170baf1
Compare
|
It seems that my changes broke FSharp.Core. I suppose that we have to adjust type equality check to work with the core code. |
… the new test case
T-Gro
left a comment
There was a problem hiding this comment.
⚠️ Automated Copilot Review — AI-assisted initial review. Feedback welcome.
[Breaking Changes] IsExtensionMethCompatibleWithTy has a logic gap in the TType_var branch: when the extension method's this parameter is a type variable with no CoercesTo constraint (unconstrained generic, or constrained only by struct/member/equality), the current code returns false and the method is silently excluded. This affects C# extensions like public static T Run<T>(this T x) and F# extensions with (this: 'T) or (this: 'T when 'T : struct). A type variable with no CoercesTo bounds should match any target type — the [] -> true fallback is missing.
[Test Coverage] All CE extension method tests use #SomeType (which always has a CoercesTo constraint). A test with a genuinely unconstrained 'T on the this parameter would catch the above bug.
…onstrains. Add test. Minor refactoring.
Fixes #19349
-> Fix accessibility and type-matching for pattern-based extension lookups (CE, Dispose, etc.)
Summary
This PR fixes an issue where pattern-based extension method lookups (specifically for Computation Expressions and use bindings) would incorrectly resolve methods that are either inaccessible (private/internal) or belong to incompatible types.
Problem
Previously, the compiler's name resolution for CE-specific methods (like Bind, Delay, Run, etc.) and the Dispose pattern for resource cleanup was overly optimistic. It often bypassed accessibility checks, leading to incorrect method resolution or even compilation of calls to private extension methods from outside their scope.
Checklist