Skip to content

Commit af22ce2

Browse files
authored
Normalise the types for Type Mismatch Error (E007) (#22337)
Closes #22333
2 parents 492c0e6 + dd6b6db commit af22ce2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/reporting/messages.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
343343
val (found2, expected2) =
344344
if (found1 frozen_<:< expected1) || reported.fbounded then (found, expected)
345345
else (found1, expected1)
346-
val (foundStr, expectedStr) = Formatting.typeDiff(found2, expected2)
346+
val (foundStr, expectedStr) = Formatting.typeDiff(found2.normalized, expected2.normalized)
347347
i"""|Found: $foundStr
348348
|Required: $expectedStr${reported.notes}"""
349349
end msg

Diff for: tests/neg/i22333.check

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i22333.scala:5:33 -------------------------------------------------------------
2+
5 |val _ = Container[(1,2,3)].guard((6, 8): Tuple.Tail[(5, 6, 8)]) // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| Found: ((6 : Int), (8 : Int))
5+
| Required: ((2 : Int), (3 : Int))
6+
|
7+
| longer explanation available when compiling with `-explain`

Diff for: tests/neg/i22333.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class Container[Rs <: Tuple]:
3+
def guard(a: Tuple.Tail[Rs]): Unit = ()
4+
5+
val _ = Container[(1,2,3)].guard((6, 8): Tuple.Tail[(5, 6, 8)]) // error

0 commit comments

Comments
 (0)