Skip to content

Commit a5ac31e

Browse files
T-GroCopilot
andcommitted
Guard backtick-escaped names in overload error range narrowing
Skip narrowing for method names that need backtick escaping, since the logical name length differs from the source text width. Also adds tests for backtick-escaped methods and multiline method access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 21562e7 commit a5ac31e

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10427,7 +10427,11 @@ and TcMethodApplication
1042710427
// Only narrow when the range is single-line and the method name fits within it.
1042810428
// Generic constructors may have internal names longer than the source text
1042910429
// (e.g., "ImmutableStack`1" vs source "ImmutableStack").
10430-
if mItem.StartLine = mItem.EndLine && methodName.Length < itemWidth then
10430+
if
10431+
mItem.StartLine = mItem.EndLine
10432+
&& methodName.Length < itemWidth
10433+
&& not (DoesIdentifierNeedBackticks methodName)
10434+
then
1043110435
let startPos = mkPos mItem.EndLine (mItem.EndColumn - methodName.Length)
1043210436
withStart startPos mItem
1043310437
else

tests/FSharp.Compiler.ComponentTests/ErrorMessages/OverloadResolutionErrorRangeTests.fs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,47 @@ Known type of argument: (unit -> string)
9797
Available overloads:
9898
- member T.Method: double -> unit // Argument at index 1 doesn't match
9999
- member T.Method: int -> unit // Argument at index 1 doesn't match") ]
100+
101+
// Verify that backtick-escaped method names fall back to the full mItem range
102+
// (methodName.Length doesn't account for backtick delimiters in source text)
103+
[<Fact>]
104+
let ``Issue 14284 - backtick-escaped method name falls back to full range`` () =
105+
FSharp
106+
"""
107+
type T() =
108+
static member Instance = T()
109+
110+
member _.``My Method``(_: double) = ()
111+
member _.``My Method``(_: int) = ()
112+
113+
T.Instance.``My Method``("")
114+
"""
115+
|> typecheck
116+
|> shouldFail
117+
|> withDiagnostics
118+
[ (Error 41, Line 8, Col 1, Line 8, Col 25, "No overloads match for method 'My Method'.
119+
120+
Known type of argument: string
121+
122+
Available overloads:
123+
- member T.``My Method`` : double -> unit // Argument at index 1 doesn't match
124+
- member T.``My Method`` : int -> unit // Argument at index 1 doesn't match") ]
125+
126+
// Verify multiline method access falls back to mItem range
127+
[<Fact>]
128+
let ``Issue 14284 - multiline method access falls back to mItem`` () =
129+
FSharp
130+
"""
131+
type T() =
132+
static member Instance = T()
133+
134+
member _.Method(_: double) = ()
135+
member _.Method(_: int) = ()
136+
137+
T
138+
.Instance
139+
.Method("")
140+
"""
141+
|> typecheck
142+
|> shouldFail
143+
|> withErrorCode 41

0 commit comments

Comments
 (0)