Fix #19664: Static extension overload resolution for generic types#19736
Fix #19664: Static extension overload resolution for generic types#19736T-Gro wants to merge 2 commits into
Conversation
…ad resolution with explicit type args) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…r (TDD green) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❗ Release notes required
Warning No PR link found in some release notes, please consider adding it.
|
|
🔍 Tooling Safety Check — Bypassed (non-fork) (scanned-sha)1d647200b286e43951fb9462fcf29579bc3809d9(/scanned-sha)
|
T-Gro
left a comment
There was a problem hiding this comment.
Review – well-targeted fix with clear comments, good regression test, and correct release notes. LGTM.
Summary of the change: When resolving Type<TArg>.Member(...), the resolver enters via dot-expression form (LookupIsInstance.Yes) but TryFindIntrinsicNamedItemOfType returns all matching methods regardless of instance/static. The extension method lookup then applies the strict instance-only filter, missing static extensions. The fix detects when the intrinsic set contradicts the filter and relaxes to Ambivalent, allowing static extensions to participate in overload resolution.
Minor observations (non-blocking):
-
Ambivalent branch in the
isAmbivalentcheck – TheLookupIsInstance.Ambivalent -> truecase meansList.existsreturns true for any non-emptyminfos, then re-assignsisInstanceFilter = Ambivalent(already its value). This is harmless but reads slightly confusingly. You could simplify to only check theYes/Nocases:
\\sharp
let isInstanceFilter =
match isInstanceFilter with
| LookupIsInstance.Ambivalent -> isInstanceFilter
| LookupIsInstance.Yes when minfos |> List.exists (fun m -> not m.IsInstance) ->
LookupIsInstance.Ambivalent
| LookupIsInstance.No when minfos |> List.exists (fun m -> m.IsInstance) ->
LookupIsInstance.Ambivalent
| _ -> isInstanceFilter
\
Purely a readability suggestion – the current code is functionally correct. -
Property-branch symmetry – The
PropertyItemarm (line ~2818) and the RFC-1137 extension-method lookup (line ~2864) both useisInstanceFilterwithout this relaxation. If a similar scenario can occur with static extension properties on generic types via explicit type args, the same fix may be needed there. Not required for this PR though. -
Release-notes entry – minor: once merged, add the PR link (
[PR #19736](...)) to match the other entries in the file.
Fixes #19664
When resolving
Type<TArg>.Member(...), the name resolver usesLookupIsInstance.Yes(dot-expression form) but finds static intrinsic members. The extension member lookup then also filters for instance-only extensions, missing the static extension overloads entirely.The fix detects this mismatch and relaxes the filter to
LookupIsInstance.Ambivalentso static extensions are included in overload resolution.