Skip to content
Open
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
Expand Up @@ -3,6 +3,7 @@
* Fix attributes on return type of unparenthesized tuple methods being silently dropped from IL. ([Issue #462](https://github.com/dotnet/fsharp/issues/462), [PR #19714](https://github.com/dotnet/fsharp/pull/19714))
* Fix internal error FS0073 "Undefined or unsolved type variable" in IlxGen when nested inline SRTP functions with multiple overloads leave unsolved typars in the non-witness codegen path. ([Issue #19709](https://github.com/dotnet/fsharp/issues/19709), [PR #19710](https://github.com/dotnet/fsharp/pull/19710))
* Fix NRE when calling virtual Object methods on value types through inline SRTP functions. ([Issue #8098](https://github.com/dotnet/fsharp/issues/8098), [PR #19511](https://github.com/dotnet/fsharp/pull/19511))
* Narrow overload-resolution error ranges to the 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 attributes not resolved from opened namespaces in `namespace rec` / `module rec` scopes. ([Issue #7931](https://github.com/dotnet/fsharp/issues/7931), [PR #19502](https://github.com/dotnet/fsharp/pull/19502))
* 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))
Expand Down
73 changes: 37 additions & 36 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4195,13 +4195,19 @@ let private ResolveExprDotLongIdent (ncenv: NameResolver) m ad nenv ty (id: Iden
ForceRaise adhocDotSearchAccessible

let ComputeItemRange wholem (lid: Ident list) rest =
match rest with
| [] -> wholem
| _ ->
let ids = List.truncate (max 0 (lid.Length - rest.Length)) lid
match ids with
let itemRange =
match rest with
| [] -> wholem
| _ -> rangeOfLid ids
| _ ->
let ids = List.truncate (max 0 (lid.Length - rest.Length)) lid
match ids with
| [] -> wholem
| _ -> rangeOfLid ids
let itemIdentRange =
match rest, lid with
| [], _ :: _ -> (List.last lid).idRange
| _ -> itemRange
itemRange, itemIdentRange

/// Filters method groups that will be sent to Visual Studio IntelliSense
/// to include only static/instance members
Expand Down Expand Up @@ -4249,7 +4255,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso
match ResolveExprLongIdent sink ncenv wholem ad nenv typeNameResInfo lid maybeAppliedArgExpr with
| Exception e -> Exception e
| Result (tinstEnclosing, item1, rest) ->
let itemRange = ComputeItemRange wholem lid rest
let itemRange, itemIdentRange = ComputeItemRange wholem lid rest

let item = FilterMethodGroups ncenv itemRange item1 true

Expand Down Expand Up @@ -4308,7 +4314,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso
callSink (item, emptyTyparInst)
AfterResolution.DoNothing

success (tinstEnclosing, item, itemRange, rest, afterResolution)
success (tinstEnclosing, item, itemRange, itemIdentRange, rest, afterResolution)

[<return: Struct>]
let (|NonOverridable|_|) namedItem =
Expand All @@ -4326,11 +4332,11 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes
| id :: rest ->
ResolveExprDotLongIdent ncenv wholem ad nenv ty id rest typeNameResInfo findFlag maybeAppliedArgExpr
| _ -> error(InternalError("ResolveExprDotLongIdentAndComputeRange", wholem))
let itemRange = ComputeItemRange wholem lid rest
resInfo, item, rest, itemRange
let itemRange, itemIdentRange = ComputeItemRange wholem lid rest
resInfo, item, rest, itemRange, itemIdentRange

// "true" resolution
let resInfo, item, rest, itemRange = resolveExpr findFlag
let resInfo, item, rest, itemRange, itemIdentRange = resolveExpr findFlag
ResolutionInfo.SendEntityPathToSink(sink, ncenv, nenv, ItemOccurrence.Use, ad, resInfo, ResultTyparChecker(fun () -> CheckAllTyparsInferrable ncenv.amap itemRange item))

// Record the precise resolution of the field for intellisense/goto definition
Expand All @@ -4345,7 +4351,7 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes
| _, NonOverridable() -> item, itemRange, false
| FindMemberFlag.IgnoreOverrides, _
| FindMemberFlag.DiscardOnFirstNonOverride, _ ->
let _, item, _, itemRange = resolveExpr FindMemberFlag.PreferOverrides
let _, item, _, itemRange, _ = resolveExpr FindMemberFlag.PreferOverrides
item, itemRange, true

let callSink (refinedItem, tpinst) =
Expand Down Expand Up @@ -4378,7 +4384,7 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes
callSink (unrefinedItem, emptyTyparInst)
AfterResolution.DoNothing

item, itemRange, rest, afterResolution
item, itemRange, itemIdentRange, rest, afterResolution


//-------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ val internal ResolvePartialLongIdentToClassOrRecdFields:
val internal ResolveRecordOrClassFieldsOfType: NameResolver -> range -> AccessorDomain -> TType -> bool -> Item list

/// Resolve a long identifier occurring in an expression position.
/// Also returns the terminal identifier range for narrower overload error ranges.
val internal ResolveLongIdentAsExprAndComputeRange:
sink: TcResultsSink ->
ncenv: NameResolver ->
Expand All @@ -887,9 +888,10 @@ val internal ResolveLongIdentAsExprAndComputeRange:
typeNameResInfo: TypeNameResolutionInfo ->
lid: Ident list ->
maybeAppliedArgExpr: SynExpr option ->
ResultOrException<EnclosingTypeInst * Item * range * Ident list * AfterResolution>
ResultOrException<EnclosingTypeInst * Item * range * range * Ident list * AfterResolution>

/// Resolve a long identifier occurring in an expression position, qualified by a type.
/// Also returns the terminal identifier range for narrower overload error ranges.
val internal ResolveExprDotLongIdentAndComputeRange:
sink: TcResultsSink ->
ncenv: NameResolver ->
Expand All @@ -902,7 +904,7 @@ val internal ResolveExprDotLongIdentAndComputeRange:
findFlag: FindMemberFlag ->
staticOnly: bool ->
maybeAppliedArgExpr: SynExpr option ->
Item * range * Ident list * AfterResolution
Item * range * range * Ident list * AfterResolution

/// A generator of type instantiations used when no more specific type instantiation is known.
val FakeInstantiationGenerator: range -> Typar list -> TType list
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,166 @@
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") ]

[<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") ]

[<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") ]

[<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") ]

[<Fact>]
let ``Issue 14284 - backtick-escaped method name`` () =
FSharp
"""
type T() =
static member Instance = T()

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

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

Known type of argument: string

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

[<Fact>]
let ``Issue 14284 - multiline method access`` () =
FSharp
"""
type T() =
static member Instance = T()

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

T
.Instance
.Method("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 10, Col 4, Line 10, Col 10, "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") ]

[<Fact>]
let ``Issue 14284 - constructor overload error`` () =
FSharp
"""
module M =
type T =
new(_: int) = {}
new(_: double) = {}

M.T("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics
[ (Error 41, Line 7, Col 3, Line 7, Col 4, "No overloads match for method 'T'.

Known type of argument: string

Available overloads:
- new: double -> M.T // Argument at index 1 doesn't match
- new: int -> M.T // Argument at index 1 doesn't match") ]
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,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
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
Loading
Loading