Skip to content

Commit

Permalink
No matching overload error uses an accurate range
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Aug 17, 2024
1 parent 6e6cf3e commit 145bf25
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10133,7 +10133,7 @@ and TcMethodApplication
CanonicalizePartialInferenceProblem cenv.css denv mItem
(unnamedCurriedCallerArgs |> List.collectSquared (fun callerArg -> freeInTypeLeftToRight g false callerArg.CallerArgumentType))

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

match afterResolution, result with
| AfterResolution.DoNothing, _ -> ()
Expand Down
10 changes: 7 additions & 3 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4063,7 +4063,11 @@ let private ResolveExprDotLongIdent (ncenv: NameResolver) m ad nenv ty (id: Iden
| _ ->
ForceRaise adhocDotSearchAccessible

let ComputeItemRange wholem (lid: Ident list) rest =
let ComputeItemRange (item: Item) wholem (lid: Ident list) rest =
match item, lid with
| Item.MethodGroup _, [ methodIdent ] -> methodIdent.idRange
| _ ->

match rest with
| [] -> wholem
| _ ->
Expand Down Expand Up @@ -4118,7 +4122,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 = ComputeItemRange item1 wholem lid rest

let item = FilterMethodGroups ncenv itemRange item1 true

Expand Down Expand Up @@ -4188,7 +4192,7 @@ 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
let itemRange = ComputeItemRange item wholem lid rest
resInfo, item, rest, itemRange

// "true" resolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module AccessibilityAnnotations_Basic =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 629, Line 11, Col 24, Line 11, Col 41, "Method 'MemberwiseClone' is not accessible from this code location")
(Error 629, Line 11, Col 26, Line 11, Col 41, "Method 'MemberwiseClone' is not accessible from this code location")
]

//SOURCE=E_MoreAccessibleBaseClass01.fs # E_MoreAccessibleBaseClass01.fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ module CustomAttributes_AttributeUsage =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 685, Line 14, Col 1, Line 14, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 26, Col 1, Line 26, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 28, Col 1, Line 28, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 14, Col 3, Line 14, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 26, Col 3, Line 26, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 28, Col 3, Line 28, Col 6, "The generic function 'Foo' must be given explicit type argument(s)")
]

// SOURCE=E_RequiresExplicitTypeArguments02.fs SCFLAGS="--test:ErrorRanges" # E_RequiresExplicitTypeArguments02.fs
Expand All @@ -281,7 +281,7 @@ module CustomAttributes_AttributeUsage =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 685, Line 20, Col 5, Line 20, Col 10, "The generic function 'Foo' must be given explicit type argument(s)")
(Error 685, Line 20, Col 7, Line 20, Col 10, "The generic function 'Foo' must be given explicit type argument(s)")
]

// SOURCE=E_WithBitwiseOr01.fsx SCFLAGS="--test:ErrorRanges -a" # E_WithBitwiseOr01.fsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,25 @@ type A() =
default this.M() = ()
"""
|> typecheck
|> shouldSucceed
|> shouldSucceed

[<Fact>]
let ``No matching overload error uses an accurate range``() =
FSharp """
type T() =
static member Instance = T()
member _.Method(_: double) = ()
member _.Method(_: int) = ()
T.Instance.Method("")
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 41, Line 6, Col 12, Line 6, 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")
]
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ let main _ =
|> compile
|> shouldFail
|> withDiagnostics [
Error 810, Line 9, Col 5, Line 9, Col 21, "Cannot call 'set_GetInit' - a setter for init-only property, please use object initialization instead. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
Error 810, Line 9, Col 10, Line 9, Col 21, "Cannot call 'set_GetInit' - a setter for init-only property, please use object initialization instead. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
]

[<FactForNETCOREAPP>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ let ``Consumption of nullable C# - no generics, just strings in methods and fiel
|> compile
|> shouldFail
|> withDiagnostics [
Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."
Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 14, Col 34, Line 14, Col 62, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 16, Col 35, Line 16, Col 39, "Nullness warning: The type 'string' does not support 'null'."
Error 3261, Line 25, Col 85, Line 25, Col 97, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 28, Col 99, Line 28, Col 111, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 30, Col 97, Line 30, Col 109, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."]
(Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability.")
(Error 3261, Line 5, Col 40, Line 5, Col 83, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability.")
(Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability.")
(Error 3261, Line 14, Col 34, Line 14, Col 62, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability.")
(Error 3261, Line 16, Col 35, Line 16, Col 39, "Nullness warning: The type 'string' does not support 'null'.")
(Error 3261, Line 25, Col 85, Line 25, Col 97, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability.");
(Error 3261, Line 28, Col 99, Line 28, Col 111, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability.")
(Error 3261, Line 30, Col 97, Line 30, Col 109, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability.")
]

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ c.Update()
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 9, Col 1, Line 9, Col 9, "This construct is deprecated. Use B instead")
(Error 101, Line 9, Col 3, Line 9, Col 9, "This construct is deprecated. Use B instead")
]

[<Fact>]
Expand All @@ -89,7 +89,7 @@ c.Update()
|> shouldFail
|> withDiagnostics [
(Error 101, Line 8, Col 9, Line 8, Col 10, "This construct is deprecated. Use B instead");
(Error 101, Line 9, Col 1, Line 9, Col 9, "This construct is deprecated. Use B instead")
(Error 101, Line 9, Col 3, Line 9, Col 9, "This construct is deprecated. Use B instead")
]

[<Fact>]
Expand All @@ -110,7 +110,7 @@ c.Update()
|> shouldFail
|> withDiagnostics [
(Error 101, Line 9, Col 9, Line 9, Col 10, "This construct is deprecated. Use B instead");
(Error 101, Line 10, Col 1, Line 10, Col 9, "This construct is deprecated. Use B instead")
(Error 101, Line 10, Col 3, Line 10, Col 9, "This construct is deprecated. Use B instead")
]

[<Fact>]
Expand Down Expand Up @@ -149,7 +149,7 @@ c.Update()
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 10, Col 1, Line 10, Col 9, "This construct is deprecated. Use B instead")
(Error 101, Line 10, Col 3, Line 10, Col 9, "This construct is deprecated. Use B instead")
]

[<Fact>]
Expand Down Expand Up @@ -596,7 +596,7 @@ b.text("Hello 2") |> ignore
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 16, Col 1, Line 16, Col 7, "This construct is deprecated. Use B instead")
(Error 101, Line 16, Col 3, Line 16, Col 7, "This construct is deprecated. Use B instead")
]

[<Fact>]
Expand Down Expand Up @@ -1188,7 +1188,7 @@ let f (x: IFirst) = x.F()
|> typecheck
|> shouldFail
|> withDiagnostics [
(Warning 44, Line 13, Col 21, Line 13, Col 24, "This construct is deprecated. Use G instead")
(Warning 44, Line 13, Col 23, Line 13, Col 24, "This construct is deprecated. Use G instead");
(Warning 44, Line 13, Col 21, Line 13, Col 26, "This construct is deprecated. Use G instead")
]

Expand All @@ -1212,7 +1212,7 @@ let f (x: IFirst) = x.F()
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 101, Line 13, Col 21, Line 13, Col 24, "This construct is deprecated. Use G instead")
(Error 101, Line 13, Col 23, Line 13, Col 24, "This construct is deprecated. Use G instead")
]

[<Fact>]
Expand All @@ -1236,7 +1236,7 @@ let f (x: IFirst) = x.F()
|> withDiagnostics [
(Warning 44, Line 9, Col 11, Line 9, Col 17, "This construct is deprecated. Use G instead")
(Warning 44, Line 13, Col 11, Line 13, Col 17, "This construct is deprecated. Use G instead")
(Warning 44, Line 13, Col 21, Line 13, Col 24, "This construct is deprecated. Use G instead")
(Warning 44, Line 13, Col 23, Line 13, Col 24, "This construct is deprecated. Use G instead")
]

[<Fact>]
Expand Down

0 comments on commit 145bf25

Please sign in to comment.