File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import core.Flags._
10
10
import core .Decorators ._
11
11
import core .StdNames .nme
12
12
import ast .Trees ._
13
+ import dotty .tools .dotc .ast .tpd
14
+ import dotty .tools .dotc .core .Constants ._
13
15
14
16
/** This phase rewrites idempotent expressions with constant types to Literals.
15
17
* The constant types are eliminated by erasure, so we need to keep
@@ -70,4 +72,19 @@ class Literalize extends MiniPhaseTransform { thisTransform =>
70
72
case ConstantType (const) if tree.const.value != const.value => Literal (const)
71
73
case _ => tree
72
74
}
75
+
76
+ /** Check that all literals have types matchin underlying constants
77
+ */
78
+ override def checkPostCondition (tree : Tree )(implicit ctx : Context ): Unit = {
79
+ tree match {
80
+ case Literal (c @ Constant (treeValue)) =>
81
+ tree.tpe match {
82
+ case ConstantType (typeValue) =>
83
+ assert(treeValue == typeValue.value, i " Type of Literal $tree is inconsistent with underlying constant " )
84
+ case tpe =>
85
+ assert(c.tpe =:= tpe, i " Type of Literal $tree is inconsistent with underlying constant type ${c.tpe}" )
86
+ }
87
+ case _ =>
88
+ }
89
+ }
73
90
}
You can’t perform that action at this time.
0 commit comments