@@ -23,7 +23,11 @@ object ConstFold:
23
23
nme.ADD , nme.SUB , nme.MUL , nme.DIV , nme.MOD )
24
24
25
25
val foldedUnops = Set [Name ](
26
- nme.UNARY_! , nme.UNARY_~ , nme.UNARY_+ , nme.UNARY_- )
26
+ nme.UNARY_! , nme.UNARY_~ , nme.UNARY_+ , nme.UNARY_- ,
27
+ nme.toChar, nme.toInt, nme.toFloat, nme.toLong, nme.toDouble,
28
+ // toByte and toShort are NOT included because we cannot write
29
+ // the type of a constant byte or short
30
+ )
27
31
28
32
def Apply [T <: Apply ](tree : T )(using Context ): T =
29
33
tree.fun match
@@ -89,6 +93,12 @@ object ConstFold:
89
93
case (nme.UNARY_- , FloatTag ) => Constant (- x.floatValue)
90
94
case (nme.UNARY_- , DoubleTag ) => Constant (- x.doubleValue)
91
95
96
+ case (nme.toChar , _ ) if x.isNumeric => Constant (x.charValue)
97
+ case (nme.toInt , _ ) if x.isNumeric => Constant (x.intValue)
98
+ case (nme.toLong , _ ) if x.isNumeric => Constant (x.longValue)
99
+ case (nme.toFloat , _ ) if x.isNumeric => Constant (x.floatValue)
100
+ case (nme.toDouble, _ ) if x.isNumeric => Constant (x.doubleValue)
101
+
92
102
case _ => null
93
103
}
94
104
0 commit comments