Skip to content

Fix accessibility and type-matching for generic extension method lookups#19536

Merged
T-Gro merged 17 commits intodotnet:mainfrom
evgTSV:fix-overloads-checking
Apr 28, 2026
Merged

Fix accessibility and type-matching for generic extension method lookups#19536
T-Gro merged 17 commits intodotnet:mainfrom
evgTSV:fix-overloads-checking

Conversation

@evgTSV
Copy link
Copy Markdown
Contributor

@evgTSV evgTSV commented Mar 31, 2026

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

  • Test cases added
  • Release notes entry updated:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

@evgTSV evgTSV force-pushed the fix-overloads-checking branch from 3f7dd89 to 170baf1 Compare March 31, 2026 21:21
@evgTSV
Copy link
Copy Markdown
Contributor Author

evgTSV commented Apr 1, 2026

It seems that my changes broke FSharp.Core. I suppose that we have to adjust type equality check to work with the core code.

Comment thread src/Compiler/Checking/NameResolution.fs Outdated
Comment thread src/Compiler/Checking/NameResolution.fs Outdated
Copy link
Copy Markdown
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Apr 10, 2026
@T-Gro T-Gro self-requested a review April 10, 2026 13:48
@evgTSV evgTSV changed the title Enhance the NameResolution System Fix accessibility and type-matching for generic extension method lookups Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Unexpected type inference for Run method - generic constraints are checked too late

3 participants