diff options
Diffstat (limited to 'src/dotty/tools/dotc/transform/Literalize.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/Literalize.scala | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/Literalize.scala b/src/dotty/tools/dotc/transform/Literalize.scala index 622ad7fc8..fa7777f81 100644 --- a/src/dotty/tools/dotc/transform/Literalize.scala +++ b/src/dotty/tools/dotc/transform/Literalize.scala @@ -10,6 +10,8 @@ import core.Flags._ import core.Decorators._ import core.StdNames.nme import ast.Trees._ +import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.core.Constants._ /** This phase rewrites idempotent expressions with constant types to Literals. * The constant types are eliminated by erasure, so we need to keep @@ -70,4 +72,19 @@ class Literalize extends MiniPhaseTransform { thisTransform => case ConstantType(const) if tree.const.value != const.value => Literal(const) case _ => tree } + + /** Check that all literals have types matchin underlying constants + */ + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { + tree match { + case Literal(c @ Constant(treeValue)) => + tree.tpe match { + case ConstantType(typeValue) => + assert(treeValue == typeValue.value, i"Type of Literal $tree is inconsistent with underlying constant") + case tpe => + assert(c.tpe =:= tpe, i"Type of Literal $tree is inconsistent with underlying constant type ${c.tpe}") + } + case _ => + } + } }
\ No newline at end of file |