Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.100.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fixed

* Narrow 'No overloads match for method' error range to method name only instead of covering the entire expression. ([Issue #14284](https://github.com/dotnet/fsharp/issues/14284), [PR #19505](https://github.com/dotnet/fsharp/pull/19505))
* Fix DU case names matching IWSAM member names no longer cause duplicate property entries. (Issue [#14321](https://github.com/dotnet/fsharp/issues/14321), [PR #19341](https://github.com/dotnet/fsharp/pull/19341))
* Fix DefaultAugmentation(false) duplicate entry in method table. (Issue [#16565](https://github.com/dotnet/fsharp/issues/16565), [PR #19341](https://github.com/dotnet/fsharp/pull/19341))
* Fix abstract event accessors now have SpecialName flag. (Issue [#5834](https://github.com/dotnet/fsharp/issues/5834), [PR #19341](https://github.com/dotnet/fsharp/pull/19341))
Expand Down
20 changes: 20 additions & 0 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10401,6 +10401,26 @@ and TcMethodApplication

let result, errors = ResolveOverloadingForCall denv cenv.css mMethExpr methodName callerArgs ad postArgumentTypeCheckingCalledMethGroup true returnTy

// Narrow the error range for unresolved overloading from the whole expression (mMethExpr)
// to just the method name. For instance calls like T.Instance.Method(""), mItem covers
// the entire "T.Instance.Method" range, so we compute the method-name-only range from
// the end of mItem and the method name length. See https://github.com/dotnet/fsharp/issues/14284.
let errors =
match errors with
| ErrorResult(warns, UnresolvedOverloading(denvErr, callerArgsErr, failure, _mWide)) ->
let mMethodName =
let itemWidth = mItem.EndColumn - mItem.StartColumn
// Only narrow when the range is single-line and the method name fits within it.
// Generic constructors may have internal names longer than the source text
// (e.g., "ImmutableStack`1" vs source "ImmutableStack").
if mItem.StartLine = mItem.EndLine && methodName.Length < itemWidth then
let startPos = mkPos mItem.EndLine (mItem.EndColumn - methodName.Length)
withStart startPos mItem
else
mItem
ErrorResult(warns, UnresolvedOverloading(denvErr, callerArgsErr, failure, mMethodName))
| other -> other

match afterResolution, result with
| AfterResolution.DoNothing, _ -> ()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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.
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.

Known type of argument: 'a list

Candidates:
- new: col: 'b -> ImmutableStack<'a>
- private new: items: 'a list -> ImmutableStack<'a>
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.
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.

Known type of argument: 'a list

Candidates:
- new: col: 'b -> ImmutableStack<'a>
- private new: items: 'a list -> ImmutableStack<'a>
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.
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.

Known type of argument: 'a list

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module ErrorMessages.OverloadResolutionErrorRangeTests

open Xunit
open FSharp.Test.Compiler

// https://github.com/dotnet/fsharp/issues/14284
[<Fact>]
let ``Issue 14284 - overload error should cover only method name, not full expression`` () =
FSharp
"""
type T() =
static member Instance = T()

member _.Method(_: double) = ()
member _.Method(_: int) = ()

T.Instance.Method("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 8, Col 12, Line 8, Col 18, "No overloads match for method 'Method'.

Known type of argument: string

Available overloads:
- member T.Method: double -> unit // Argument at index 1 doesn't match
- member T.Method: int -> unit // Argument at index 1 doesn't match") ]

// Verify that the error range is narrow also for simple direct method calls
[<Fact>]
let ``Issue 14284 - overload error for simple static method`` () =
FSharp
"""
type T() =
static member Method(_: double) = ()
static member Method(_: int) = ()

T.Method("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 6, Col 3, Line 6, Col 9, "No overloads match for method 'Method'.

Known type of argument: string

Available overloads:
- static member T.Method: double -> unit // Argument at index 1 doesn't match
- static member T.Method: int -> unit // Argument at index 1 doesn't match") ]

// Verify that a long expression before the method doesn't widen the error range
[<Fact>]
let ``Issue 14284 - overload error on chained expression`` () =
FSharp
"""
type T() =
static member Instance = T()

member _.Next = T()
member _.Method(_: double) = ()
member _.Method(_: int) = ()

T.Instance.Next.Next.Method("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 9, Col 22, Line 9, Col 28, "No overloads match for method 'Method'.

Known type of argument: string

Available overloads:
- member T.Method: double -> unit // Argument at index 1 doesn't match
- member T.Method: int -> unit // Argument at index 1 doesn't match") ]

// Verify error range with lambda argument
[<Fact>]
let ``Issue 14284 - overload error with lambda argument`` () =
FSharp
"""
type T() =
static member Instance = T()

member _.Method(_: double) = ()
member _.Method(_: int) = ()

T.Instance.Method(fun () -> "")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 8, Col 12, Line 8, Col 18, "No overloads match for method 'Method'.

Known type of argument: (unit -> string)

Available overloads:
- member T.Method: double -> unit // Argument at index 1 doesn't match
- member T.Method: int -> unit // Argument at index 1 doesn't match") ]
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
<Compile Include="ErrorMessages\MissingExpressionTests.fs" />
<Compile Include="ErrorMessages\ModuleTests.fs" />
<Compile Include="ErrorMessages\DiagnosticRegressionTests.fs" />
<Compile Include="ErrorMessages\OverloadResolutionErrorRangeTests.fs" />
<Compile Include="ErrorMessages\NameResolutionTests.fs" />
<Compile Include="ErrorMessages\SuggestionsTests.fs" />
<Compile Include="ErrorMessages\TypeMismatchTests.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Math.Max(a,)
dumpDiagnosticNumbers checkResults |> shouldEqual [
"(4,10--4,11)", 3100
"(4,9--4,10)", 39
"(4,0--4,12)", 41
"(4,5--4,8)", 41
]

assertHasSymbolUsages ["Max"] checkResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ let test2(x: 'T) =
[|
(FSharpDiagnosticSeverity.Error,
41,
(11, 5, 11, 11),
(11, 7, 11, 8),
"""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.

Known type of argument: 'T
Expand All @@ -341,7 +341,7 @@ Candidates:
- static member M.A: n: int -> unit""")
(FSharpDiagnosticSeverity.Error,
41,
(19, 5, 19, 12),
(19, 8, 19, 9),
"""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.

Known type of argument: 'T
Expand All @@ -368,7 +368,7 @@ let test(x: 'T) =
"""
FSharpDiagnosticSeverity.Error
41
(10, 5, 10, 11)
(10, 7, 10, 8)
"""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.

Known type of argument: 'T
Expand Down Expand Up @@ -495,7 +495,7 @@ let test() = M.A(System.DateTime.UtcNow, 1)
"""
FSharpDiagnosticSeverity.Error
41
(6, 14, 6, 44)
(6, 16, 6, 17)
"""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.

Known types of arguments: System.DateTime * int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ E_RigidTypeAnnotation03.fsx(17,13,17,16): typecheck error FS0001: This expressio
but here has type
'byte'

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

Known type of argument: sbyte

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

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

Known type of argument: float32

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

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

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

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

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

Known type of argument: char

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

Known type of argument: 'a

Expand All @@ -18,7 +18,7 @@ Candidates:
- System.Console.WriteLine(value: uint32) : unit
- System.Console.WriteLine(value: uint64) : unit

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

Known type of argument: 'a

Expand Down
4 changes: 2 additions & 2 deletions tests/fsharp/conformance/inference/E_OneTypeVariable03.bsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

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

Known types of arguments: 'a * int

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

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

Known types of arguments: 'a * int

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

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

Known types of arguments: 'a * int

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

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

Known types of arguments: 'a * int

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

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

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

Known types of arguments: 'a * 'b

Expand Down
Loading
Loading