Skip to content

Commit 02e2ca2

Browse files
committed
Check not only value equality of constants in Literalize postcondition but also type eqality
1 parent d220558 commit 02e2ca2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/dotty/tools/dotc/transform/Literalize.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ class Literalize extends MiniPhaseTransform { thisTransform =>
7373
case _ => tree
7474
}
7575

76-
/** Check that all literals have types matchin underlying constants
76+
/** Check that all literals have types match underlying constants
7777
*/
7878
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = {
7979
tree match {
8080
case Literal(c @ Constant(treeValue)) =>
8181
tree.tpe match {
82-
case ConstantType(typeValue) =>
83-
assert(treeValue == typeValue.value, i"Type of Literal $tree is inconsistent with underlying constant")
82+
case ConstantType(c2 @ Constant(typeValue)) =>
83+
assert(treeValue == typeValue && c2.tag == c.tag,
84+
i"Type of Literal $tree is inconsistent with underlying constant")
8485
case tpe =>
8586
assert(c.tpe =:= tpe, i"Type of Literal $tree is inconsistent with underlying constant type ${c.tpe}")
8687
}

0 commit comments

Comments
 (0)