Skip to content

Commit 53645d1

Browse files
authoredMar 18, 2025
Merge pull request #179 from scala/backport-lts-3.3-22337
Backport "Normalise the types for Type Mismatch Error (E007)" to 3.3 LTS
2 parents 15a801f + 6f68a80 commit 53645d1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

‎compiler/src/dotty/tools/dotc/reporting/messages.scala

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

‎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`

‎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)
Failed to load comments.