aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/Literalize.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-12-17 12:35:26 +0100
committerMartin Odersky <odersky@gmail.com>2014-12-17 12:35:30 +0100
commita098fd360a3ef2d1eac86de695412054ec558f6e (patch)
tree30604595891a8e709bcae2314b79645e7ef52255 /src/dotty/tools/dotc/transform/Literalize.scala
parent3a68e50073e9c4cef06c44e1dec7e3e492eb3274 (diff)
downloaddotty-a098fd360a3ef2d1eac86de695412054ec558f6e.tar.gz
dotty-a098fd360a3ef2d1eac86de695412054ec558f6e.tar.bz2
dotty-a098fd360a3ef2d1eac86de695412054ec558f6e.zip
Fix #300: Make literals have the same constants as their types.
Diffstat (limited to 'src/dotty/tools/dotc/transform/Literalize.scala')
-rw-r--r--src/dotty/tools/dotc/transform/Literalize.scala8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/Literalize.scala b/src/dotty/tools/dotc/transform/Literalize.scala
index 99b4b173b..622ad7fc8 100644
--- a/src/dotty/tools/dotc/transform/Literalize.scala
+++ b/src/dotty/tools/dotc/transform/Literalize.scala
@@ -14,6 +14,9 @@ import ast.Trees._
/** This phase rewrites idempotent expressions with constant types to Literals.
* The constant types are eliminated by erasure, so we need to keep
* the info about constantness in the trees.
+ *
+ * The phase also makes sure that the constant of a literal is the same as the constant
+ * in the type of the literal.
*/
class Literalize extends MiniPhaseTransform { thisTransform =>
import ast.tpd._
@@ -62,4 +65,9 @@ class Literalize extends MiniPhaseTransform { thisTransform =>
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo): Tree =
literalize(tree)
+
+ override def transformLiteral(tree: Literal)(implicit ctx: Context, info: TransformerInfo): Tree = tree.tpe match {
+ case ConstantType(const) if tree.const.value != const.value => Literal(const)
+ case _ => tree
+ }
} \ No newline at end of file