Skip to content

Commit 182dd57

Browse files
authored
Fix missing message with type error (FS0001) (#17516)
1 parent 97a2a75 commit 182dd57

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 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))
77
* 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))
88
* 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))
9+
* 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))
910

1011
### Added
1112

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ type Exception with
809809

810810
| ErrorFromAddingTypeEquation(error = ConstraintSolverError _ as e) -> e.Output(os, suggestNames)
811811

812-
| ErrorFromAddingTypeEquation(_g, denv, ty1, ty2, ConstraintSolverTupleDiffLengths(_, contextInfo, tl1, tl2, _, _), m) ->
812+
| ErrorFromAddingTypeEquation(_g, denv, ty1, ty2, ConstraintSolverTupleDiffLengths(_, contextInfo, tl1, tl2, m1, m2), m) ->
813813
let ty1, ty2, tpcs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
814814
let messageArgs = tl1.Length, ty1, tl2.Length, ty2
815815

@@ -826,6 +826,11 @@ type Exception with
826826
else
827827
os.AppendString(FSComp.SR.listElementHasWrongTypeTuple messageArgs)
828828
| _ -> os.AppendString(ErrorFromAddingTypeEquationTuplesE().Format tl1.Length ty1 tl2.Length ty2 tpcs)
829+
else
830+
os.AppendString(ConstraintSolverTupleDiffLengthsE().Format tl1.Length tl2.Length)
831+
832+
if m1.StartLine <> m2.StartLine then
833+
os.AppendString(SeeAlsoE().Format(stringOfRange m1))
829834

830835
| ErrorFromAddingTypeEquation(g, denv, ty1, ty2, e, _) ->
831836
if not (typeEquiv g ty1 ty2) then

tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,22 @@ let f4 =
351351
(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' ")
352352
]
353353

354+
[<Fact>]
355+
let ``Error when tuples have differing lengths and we do not know the types.``() =
356+
Fsx """
357+
let foo items =
358+
for (a,b,c) in items do
359+
printfn "%A" (a, c)
360+
361+
[<EntryPoint>]
362+
let main args =
363+
foo ({1..10} |> Seq.pairwise)
364+
0
365+
"""
366+
|> asExe
367+
|> typecheck
368+
|> shouldFail
369+
|> withDiagnostics [
370+
(Error 1, Line 8, Col 21, Line 8, Col 33, "The tuples have differing lengths of 3 and 2")
371+
]
372+

0 commit comments

Comments
 (0)