From 9eb633a570677a3ebdc9bf53b50b69454a1714fa Mon Sep 17 00:00:00 2001 From: gauthier Date: Thu, 25 Apr 2019 09:52:56 -0700 Subject: [PATCH] Overload resolution error messages: things display like I want in fsi, almost like I want in VS2019, this is for the simple non generic method overload case. I want to check if user experience changes wrt https://github.com/Microsoft/visualfsharp/issues/2503 and put some time to add tests. --- src/fsharp/CompileOps.fs | 4 ++-- src/fsharp/ConstraintSolver.fs | 13 ++++++------- src/fsharp/FSComp.txt | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 54250d66204..9f698492a31 100644 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -771,10 +771,10 @@ let OutputPhasedErrorR (os: StringBuilder) (err: PhasedDiagnostic) (canSuggestNa #endif | UnresolvedOverloading(denv, mtext, overloads, m) -> - os.AppendLine mtext |> ignore + os.Append mtext |> ignore overloads |> List.map (fun e -> e.overload.OverloadMethodInfo denv m |> FSComp.SR.formatDashItem) - |> List.iter (os.AppendLine >> ignore) + |> List.iter (os.Append >> ignore) | UnresolvedConversionOperator(denv, fromTy, toTy, _) -> let t1, t2, _tpcs = NicePrint.minimalStringsOfTwoTypes denv fromTy toTy diff --git a/src/fsharp/ConstraintSolver.fs b/src/fsharp/ConstraintSolver.fs index 166608383d0..91d9a1a2c4c 100644 --- a/src/fsharp/ConstraintSolver.fs +++ b/src/fsharp/ConstraintSolver.fs @@ -2542,24 +2542,23 @@ and ResolveOverloading function | (Some argName), typeLayout -> sprintf "(%s) : %s" argName (Display.layout_to_string formatOptions typeLayout) | _, typeLayout -> (Display.layout_to_string formatOptions typeLayout) + let nl = System.Environment.NewLine let argsMessage = match callerArgs.LayoutArgumentTypes denv with | [] -> System.String.Empty - | [item] -> Environment.NewLine + (item |> getArgType |> FSComp.SR.csNoOverloadsFoundArgumentsPrefixSingular) + | [item] -> nl + (item |> getArgType |> FSComp.SR.csNoOverloadsFoundArgumentsPrefixSingular) | items -> let args = items |> List.map (getArgType >> FSComp.SR.formatDashItem) |> List.toArray - |> String.concat Environment.NewLine + |> String.concat nl - Environment.NewLine - + Environment.NewLine + nl + nl + (FSComp.SR.csNoOverloadsFoundArgumentsPrefixPlural()) - + Environment.NewLine + + nl + args - + Environment.NewLine - + Environment.NewLine + + nl + nl //printfn "%A" argsMessage diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index a2a0df1dd14..77658e731ac 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -366,7 +366,7 @@ csNoOverloadsFoundArgumentsPrefixSingular,"Argument given: %s" csNoOverloadsFoundArgumentsPrefixPlural,"Arguments given:" csMethodIsOverloaded,"A unique overload for method '%s' could not be determined based on type information prior to this program point. A type annotation may be needed." csCandidates,"Candidates: %s" -csSeeAvailableOverloads,"The available overloads are shown below." +csSeeAvailableOverloads,"Available overloads:" 512,parsDoCannotHaveVisibilityDeclarations,"Accessibility modifiers are not permitted on 'do' bindings, but '%s' was given." 513,parsEofInHashIf,"End of file in #if section begun at or after here" 514,parsEofInString,"End of file in string begun at or before here"