From 3a5e759da2725b0f7a123e9127db57c43ad869bf Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 9 Aug 2024 21:17:20 +0100 Subject: [PATCH 1/2] Fix missing message with type error (FS0001) --- src/Compiler/Driver/CompilerDiagnostics.fs | 7 ++++++- .../ErrorMessages/TypeMismatchTests.fs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index 5ac8f448448..00c1fdec81a 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -809,7 +809,7 @@ type Exception with | ErrorFromAddingTypeEquation(error = ConstraintSolverError _ as e) -> e.Output(os, suggestNames) - | ErrorFromAddingTypeEquation(_g, denv, ty1, ty2, ConstraintSolverTupleDiffLengths(_, contextInfo, tl1, tl2, _, _), m) -> + | ErrorFromAddingTypeEquation(_g, denv, ty1, ty2, ConstraintSolverTupleDiffLengths(_, contextInfo, tl1, tl2, m1, m2), m) -> let ty1, ty2, tpcs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2 let messageArgs = tl1.Length, ty1, tl2.Length, ty2 @@ -826,6 +826,11 @@ type Exception with else os.AppendString(FSComp.SR.listElementHasWrongTypeTuple messageArgs) | _ -> os.AppendString(ErrorFromAddingTypeEquationTuplesE().Format tl1.Length ty1 tl2.Length ty2 tpcs) + else + os.AppendString(ConstraintSolverTupleDiffLengthsE().Format tl1.Length tl2.Length) + + if m1.StartLine <> m2.StartLine then + os.AppendString(SeeAlsoE().Format(stringOfRange m1)) | ErrorFromAddingTypeEquation(g, denv, ty1, ty2, e, _) -> if not (typeEquiv g ty1 ty2) then diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs index 06dc7d44671..34263b3f7bc 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs @@ -351,3 +351,22 @@ let f4 = (Error 1, Line 28, Col 9, Line 28, Col 12, "This expression was expected to have type\n 'int64' \nbut here has type\n 'float' ") ] + [] + let ``Error when tuples have differing lengths and we do not know the types.``() = + Fsx """ +let foo items = + for (a,b,c) in items do + printfn "%A" (a, c) + +[] +let main args = + foo ({1..10} |> Seq.pairwise) + 0 + """ + |> asExe + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 1, Line 8, Col 21, Line 8, Col 33, "The tuples have differing lengths of 3 and 2") + ] + From a8bc12fd6c1d6570dd3a50834f74c41a8f2cd8f4 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 10 Aug 2024 14:42:10 +0100 Subject: [PATCH 2/2] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.100.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md index f05d847075d..fd64a8f4349 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -6,6 +6,7 @@ * C# protected property can be assigned in F# inherit constructor call. ([Issue #13299](https://github.com/dotnet/fsharp/issues/13299), [PR #17391](https://github.com/dotnet/fsharp/pull/17391)) * MethodAccessException on equality comparison of a record with private fields. ([Issue #17447](https://github.com/dotnet/fsharp/issues/17447), [PR #17391](https://github.com/dotnet/fsharp/pull/17467)) * Compiler fails to recognise namespace in FQN with enabled GraphBasedChecking. ([Issue #17508](https://github.com/dotnet/fsharp/issues/17508), [PR #17510](https://github.com/dotnet/fsharp/pull/17510)) +* Fix missing message for type error (FS0001). ([Issue #17373](https://github.com/dotnet/fsharp/issues/17373), [PR #17516](https://github.com/dotnet/fsharp/pull/17516)) ### Added