File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ import ast.Trees._
14
14
/** This phase rewrites idempotent expressions with constant types to Literals.
15
15
* The constant types are eliminated by erasure, so we need to keep
16
16
* the info about constantness in the trees.
17
+ *
18
+ * The phase also makes sure that the constant of a literal is the same as the constant
19
+ * in the type of the literal.
17
20
*/
18
21
class Literalize extends MiniPhaseTransform { thisTransform =>
19
22
import ast .tpd ._
@@ -62,4 +65,9 @@ class Literalize extends MiniPhaseTransform { thisTransform =>
62
65
63
66
override def transformTypeApply (tree : TypeApply )(implicit ctx : Context , info : TransformerInfo ): Tree =
64
67
literalize(tree)
68
+
69
+ override def transformLiteral (tree : Literal )(implicit ctx : Context , info : TransformerInfo ): Tree = tree.tpe match {
70
+ case ConstantType (const) if tree.const.value != const.value => Literal (const)
71
+ case _ => tree
72
+ }
65
73
}
Original file line number Diff line number Diff line change
1
+ object Test {
2
+
3
+ val x : Double = 2
4
+ val y : Byte = 3
5
+
6
+ }
You can’t perform that action at this time.
0 commit comments