Skip to content

Suppress hover/symbol resolution for wildcard _ patterns inside member _.…#19760

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-wildcard-pattern-issue
Draft

Suppress hover/symbol resolution for wildcard _ patterns inside member _.…#19760
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-wildcard-pattern-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

When a member uses _ as its instance identifier, tooling was incorrectly treating wildcard _ patterns in the member body as references to that instance. This showed misleading hover text like val _: T for discard patterns that should resolve to nothing.

  • Compiler service resolution

    • Teach GetDeclItemsForNamesAtPosition to stop fallback identifier lookup for bare _ when precise name resolution did not produce a result.
    • This keeps wildcard patterns from being resolved through the member's synthetic _ instance identifier while preserving normal member-instance behavior elsewhere.
  • Tooltip regressions

    • Add focused service tests covering discard patterns inside member _.… bodies:
      • lambda parameter discard
      • let binding discard
    • Assert that these locations produce an empty tooltip instead of val _: T.
  • Behavioral example

    type T () =
        member _.M () =
            fun _ -> ()
            // no hover
    
        member _.N () =
            let _ = () in ()
            // no hover

Copilot AI changed the title [WIP] Fix tooling behavior for underscore wildcard patterns Suppress hover/symbol resolution for wildcard _ patterns inside member _.… May 18, 2026
Copilot finished work on behalf of T-Gro May 18, 2026 12:07
Copilot AI requested a review from T-Gro May 18, 2026 12:07
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.

Looks good overall — the fix is correct and well-scoped.

The placement of the isDiscardIdentifier guard after the NameResResult.Members(FilterRelevantItems ...) branch is exactly right: it only short-circuits the fallback lookup when precise name resolution didn't produce results, preventing the identifier _ in scope (i.e., the member's self-identifier) from being incorrectly surfaced as tooltip text for wildcard/discard patterns.

Key observations:

  • The condition (None, Some ["_"]) correctly limits this to bare _ — it won't interfere with dotted access like _.Property (which would be Some ["_"; "Property"]).
  • Since residueOpt = None is specific to the tooltip/symbol-lookup callers (not the completion path which passes Some partialName.PartialIdent), completion behavior is unaffected.
  • The fix also benefits GetSymbolUsesAtLocation and GetF1Keyword, which share the same call path — a nice consistency win.

Minor suggestions (non-blocking):

  1. A short inline comment above the guard (e.g., // Wildcard _ should not resolve to the member's synthetic self-identifier via fallback) would help future readers understand why this case is separated from the general fallback.

  2. Consider adding a test for match x with _ -> ... inside a member _.M() body — this is another common discard position where the old behavior would have shown misleading hover text.

  3. Consider a negative test confirming that a named self-identifier (e.g., member this.M() = ...; hover over 'this') is NOT affected by the fix — purely for regression confidence.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 20, 2026
@T-Gro T-Gro self-requested a review May 20, 2026 12:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 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

T-Gro and others added 3 commits May 25, 2026 14:16
- Add explanatory comment above the isDiscardIdentifier guard
- Add test for match wildcard pattern inside member _.M() body
- Add negative test confirming named self-identifier (this) is unaffected

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

Status: New

Development

Successfully merging this pull request may close these issues.

Tooling implies that _ in member body refers to the instance identifier when it is actually a wildcard pattern

2 participants