Skip to content

Commit 7d2f1e9

Browse files
T-GroCopilot
andcommitted
Fix FS0041 error range narrowing and update all test baselines
- Guard against generic constructors where internal name (e.g. ImmutableStack`1) is longer than source text, which would shift the range before the actual token - Only narrow when mItem is single-line and methodName fits within the range width - Fall back to mItem (already narrower than mMethExpr) when guard fails - Update 30+ baseline files and inline test expected ranges to match narrowed positions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 068175c commit 7d2f1e9

34 files changed

Lines changed: 216 additions & 119 deletions

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10409,8 +10409,15 @@ and TcMethodApplication
1040910409
match errors with
1041010410
| ErrorResult(warns, UnresolvedOverloading(denvErr, callerArgsErr, failure, _mWide)) ->
1041110411
let mMethodName =
10412-
let startPos = mkPos mItem.EndLine (mItem.EndColumn - methodName.Length)
10413-
withStart startPos mItem
10412+
let itemWidth = mItem.EndColumn - mItem.StartColumn
10413+
// Only narrow when the range is single-line and the method name fits within it.
10414+
// Generic constructors may have internal names longer than the source text
10415+
// (e.g., "ImmutableStack`1" vs source "ImmutableStack").
10416+
if mItem.StartLine = mItem.EndLine && methodName.Length < itemWidth then
10417+
let startPos = mkPos mItem.EndLine (mItem.EndColumn - methodName.Length)
10418+
withStart startPos mItem
10419+
else
10420+
mItem
1041410421
ErrorResult(warns, UnresolvedOverloading(denvErr, callerArgsErr, failure, mMethodName))
1041510422
| other -> other
1041610423

tests/FSharp.Compiler.ComponentTests/ConstraintSolver/neg_invalid_constructor.fs.err.bsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
neg_invalid_constructor.fs (3,29)-(3,56) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
1+
neg_invalid_constructor.fs (3,29)-(3,43) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
22

33
Known type of argument: 'a list
44

55
Candidates:
66
- new: col: 'b -> ImmutableStack<'a>
77
- private new: items: 'a list -> ImmutableStack<'a>
8-
neg_invalid_constructor.fs (4,93)-(4,111) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
8+
neg_invalid_constructor.fs (4,93)-(4,107) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
99

1010
Known type of argument: 'a list
1111

1212
Candidates:
1313
- new: col: 'b -> ImmutableStack<'a>
1414
- private new: items: 'a list -> ImmutableStack<'a>
15-
neg_invalid_constructor.fs (7,30)-(7,60) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
15+
neg_invalid_constructor.fs (7,30)-(7,44) typecheck error A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed.
1616

1717
Known type of argument: 'a list
1818

tests/fsharp/Compiler/Language/TypeDirectedConversionTests.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ let test2(x: 'T) =
329329
[|
330330
(FSharpDiagnosticSeverity.Error,
331331
41,
332-
(11, 5, 11, 11),
332+
(11, 6, 11, 7),
333333
"""A unique overload for method 'A' could not be determined based on type information prior to this program point. A type annotation may be needed.
334334
335335
Known type of argument: 'T
@@ -341,7 +341,7 @@ Candidates:
341341
- static member M.A: n: int -> unit""")
342342
(FSharpDiagnosticSeverity.Error,
343343
41,
344-
(19, 5, 19, 12),
344+
(19, 7, 19, 8),
345345
"""A unique overload for method 'A' could not be determined based on type information prior to this program point. A type annotation may be needed.
346346
347347
Known type of argument: 'T
@@ -368,7 +368,7 @@ let test(x: 'T) =
368368
"""
369369
FSharpDiagnosticSeverity.Error
370370
41
371-
(10, 5, 10, 11)
371+
(10, 6, 10, 7)
372372
"""A unique overload for method 'A' could not be determined based on type information prior to this program point. A type annotation may be needed.
373373
374374
Known type of argument: 'T
@@ -495,7 +495,7 @@ let test() = M.A(System.DateTime.UtcNow, 1)
495495
"""
496496
FSharpDiagnosticSeverity.Error
497497
41
498-
(6, 14, 6, 44)
498+
(6, 15, 6, 16)
499499
"""A unique overload for method 'A' could not be determined based on type information prior to this program point. A type annotation may be needed.
500500
501501
Known types of arguments: System.DateTime * int

tests/fsharp/conformance/expressions/syntacticsugar/E_Slices01.bsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
E_Slices01.fsx(15,9,15,19): typecheck error FS0041: A unique overload for method 'GetSlice' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_Slices01.fsx(15,11,15,19): typecheck error FS0041: A unique overload for method 'GetSlice' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known types of arguments: int * int option * 'a option
55

@@ -15,7 +15,7 @@ Candidates:
1515
- member Foo.GetSlice: x: int * y1: int option * y2: float option -> unit
1616
- member Foo.GetSlice: x: int * y1: int option * y2: int option -> unit
1717

18-
E_Slices01.fsx(17,9,17,19): typecheck error FS0041: A unique overload for method 'GetSlice' could not be determined based on type information prior to this program point. A type annotation may be needed.
18+
E_Slices01.fsx(17,11,17,19): typecheck error FS0041: A unique overload for method 'GetSlice' could not be determined based on type information prior to this program point. A type annotation may be needed.
1919

2020
Known types of arguments: 'a option * int option * int
2121

tests/fsharp/conformance/expressions/type-relatedexpressions/E_RigidTypeAnnotation03.bsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ E_RigidTypeAnnotation03.fsx(17,13,17,16): typecheck error FS0001: This expressio
44
but here has type
55
'byte'
66

7-
E_RigidTypeAnnotation03.fsx(17,9,17,25): typecheck error FS0041: No overloads match for method 'M'.
7+
E_RigidTypeAnnotation03.fsx(17,11,17,12): typecheck error FS0041: No overloads match for method 'M'.
88

99
Known type of argument: sbyte
1010

@@ -20,7 +20,7 @@ E_RigidTypeAnnotation03.fsx(18,13,18,19): typecheck error FS0001: This expressio
2020
but here has type
2121
'float<'u>'
2222

23-
E_RigidTypeAnnotation03.fsx(18,9,18,30): typecheck error FS0041: No overloads match for method 'M'.
23+
E_RigidTypeAnnotation03.fsx(18,11,18,12): typecheck error FS0041: No overloads match for method 'M'.
2424

2525
Known type of argument: float32
2626

@@ -42,7 +42,7 @@ but given a
4242
'decimal<Kg>'
4343
The unit of measure 'N s ^ 2' does not match the unit of measure 'Kg'
4444

45-
E_RigidTypeAnnotation03.fsx(20,9,20,39): typecheck error FS0041: No overloads match for method 'M'.
45+
E_RigidTypeAnnotation03.fsx(20,11,20,12): typecheck error FS0041: No overloads match for method 'M'.
4646

4747
Known type of argument: decimal<N s ^ 2>
4848

@@ -58,7 +58,7 @@ E_RigidTypeAnnotation03.fsx(21,14,21,18): typecheck error FS0001: This expressio
5858
but here has type
5959
'string'
6060

61-
E_RigidTypeAnnotation03.fsx(21,9,21,27): typecheck error FS0041: No overloads match for method 'M'.
61+
E_RigidTypeAnnotation03.fsx(21,11,21,12): typecheck error FS0041: No overloads match for method 'M'.
6262

6363
Known type of argument: char
6464

tests/fsharp/conformance/inference/E_LeftToRightOverloadResolution01.bsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
E_LeftToRightOverloadResolution01.fsx(7,23,7,51): typecheck error FS0041: A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_LeftToRightOverloadResolution01.fsx(7,38,7,47): typecheck error FS0041: A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known type of argument: 'a
55

@@ -18,7 +18,7 @@ Candidates:
1818
- System.Console.WriteLine(value: uint32) : unit
1919
- System.Console.WriteLine(value: uint64) : unit
2020

21-
E_LeftToRightOverloadResolution01.fsx(9,23,9,51): typecheck error FS0041: A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed.
21+
E_LeftToRightOverloadResolution01.fsx(9,38,9,47): typecheck error FS0041: A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed.
2222

2323
Known type of argument: 'a
2424

tests/fsharp/conformance/inference/E_OneTypeVariable03.bsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
E_OneTypeVariable03.fsx(60,34,60,44): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_OneTypeVariable03.fsx(60,38,60,39): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known types of arguments: 'a * int
55

66
Candidates:
77
- static member C23.M: x: 'a * y: 'b -> Two
88
- static member C23.M: x: 'a * y: int -> Three
99

10-
E_OneTypeVariable03.fsx(61,34,61,45): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
10+
E_OneTypeVariable03.fsx(61,39,61,40): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1111

1212
Known types of arguments: 'a * int
1313

tests/fsharp/conformance/inference/E_OneTypeVariable03rec.bsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
E_OneTypeVariable03rec.fsx(60,38,60,48): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_OneTypeVariable03rec.fsx(60,42,60,43): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known types of arguments: 'a * int
55

66
Candidates:
77
- static member C23.M: x: 'a * y: 'b -> Two
88
- static member C23.M: x: 'a * y: int -> Three
99

10-
E_OneTypeVariable03rec.fsx(61,38,61,49): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
10+
E_OneTypeVariable03rec.fsx(61,43,61,44): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1111

1212
Known types of arguments: 'a * int
1313

tests/fsharp/conformance/inference/E_TwoDifferentTypeVariables01.bsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11

2-
E_TwoDifferentTypeVariables01.fsx(61,33,61,43): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_TwoDifferentTypeVariables01.fsx(61,37,61,38): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known types of arguments: 'a * 'b
55

66
Candidates:
77
- static member C13.M: x: 'a * y: 'a -> One
88
- static member C13.M: x: 'a * y: int -> Three
99

10-
E_TwoDifferentTypeVariables01.fsx(62,33,62,43): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
10+
E_TwoDifferentTypeVariables01.fsx(62,37,62,38): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1111

1212
Known types of arguments: 'a * 'b
1313

1414
Candidates:
1515
- static member C24.M: x: 'a * y: 'b -> Two
1616
- static member C24.M: x: 'a * y: C -> Four
1717

18-
E_TwoDifferentTypeVariables01.fsx(63,33,63,47): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
18+
E_TwoDifferentTypeVariables01.fsx(63,37,63,38): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1919

2020
Known types of arguments: 'a * 'b
2121

2222
Candidates:
2323
- static member C13.M: x: 'a * y: 'a -> One
2424
- static member C13.M: x: 'a * y: int -> Three
2525

26-
E_TwoDifferentTypeVariables01.fsx(64,33,64,46): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
26+
E_TwoDifferentTypeVariables01.fsx(64,37,64,38): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2727

2828
Known types of arguments: 'a * 'b
2929

tests/fsharp/conformance/inference/E_TwoDifferentTypeVariables01rec.bsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11

2-
E_TwoDifferentTypeVariables01rec.fsx(60,37,60,47): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2+
E_TwoDifferentTypeVariables01rec.fsx(60,41,60,42): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
33

44
Known types of arguments: 'a * 'b
55

66
Candidates:
77
- static member C13.M: x: 'a * y: 'a -> One
88
- static member C13.M: x: 'a * y: int -> Three
99

10-
E_TwoDifferentTypeVariables01rec.fsx(61,37,61,47): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
10+
E_TwoDifferentTypeVariables01rec.fsx(61,41,61,42): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1111

1212
Known types of arguments: 'a * 'b
1313

1414
Candidates:
1515
- static member C24.M: x: 'a * y: 'b -> Two
1616
- static member C24.M: x: 'a * y: C -> Four
1717

18-
E_TwoDifferentTypeVariables01rec.fsx(62,37,62,51): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
18+
E_TwoDifferentTypeVariables01rec.fsx(62,41,62,42): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
1919

2020
Known types of arguments: 'a * 'b
2121

2222
Candidates:
2323
- static member C13.M: x: 'a * y: 'a -> One
2424
- static member C13.M: x: 'a * y: int -> Three
2525

26-
E_TwoDifferentTypeVariables01rec.fsx(63,37,63,50): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
26+
E_TwoDifferentTypeVariables01rec.fsx(63,41,63,42): typecheck error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed.
2727

2828
Known types of arguments: 'a * 'b
2929

0 commit comments

Comments
 (0)