From 145bf25f8afc1211c32acea8ed9f79a29cd40dde Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 17 Aug 2024 19:20:51 +0100 Subject: [PATCH] No matching overload error uses an accurate range --- .../Checking/Expressions/CheckExpressions.fs | 2 +- src/Compiler/Checking/NameResolution.fs | 10 +++++--- .../AccessibilityAnnotations/Basic/Basic.fs | 2 +- .../AttributeUsage/AttributeUsage.fs | 8 +++---- .../ErrorMessages/ClassesTests.fs | 23 ++++++++++++++++++- .../Interop/RequiredAndInitOnlyProperties.fs | 2 +- .../Nullness/NullableCsharpImportTests.fs | 16 +++++++------ .../ObsoleteAttributeCheckingTests.fs | 16 ++++++------- 8 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 8789e92797c..64773ddef5f 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -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, _ -> () diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index f1945c80928..1ed131a5103 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -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 | _ -> @@ -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 @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs index 869e4ba9930..f76552ba8d9 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs index faf1784612b..d6b307b3893 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -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 @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index 55f4d1cbf1b..60f947e82a2 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -815,4 +815,25 @@ type A() = default this.M() = () """ |> typecheck - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + + [] + 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") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs b/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs index e0c8b08e188..8917ebff2c8 100644 --- a/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs +++ b/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs @@ -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" ] [] diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableCsharpImportTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableCsharpImportTests.fs index 24ff5798cbd..980c89a8484 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableCsharpImportTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableCsharpImportTests.fs @@ -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.") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs index f31371a9653..884f285c406 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs @@ -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") ] [] @@ -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") ] [] @@ -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") ] [] @@ -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") ] [] @@ -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") ] [] @@ -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") ] @@ -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") ] [] @@ -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") ] []