@@ -23,7 +23,10 @@ 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.toByte, nme.toChar, nme.toShort, nme.toInt, nme.toFloat,
28
+ nme.toLong, nme.toDouble
29
+ )
27
30
28
31
def Apply [T <: Apply ](tree : T )(using Context ): T =
29
32
tree.fun match
@@ -89,6 +92,14 @@ object ConstFold:
89
92
case (nme.UNARY_- , FloatTag ) => Constant (- x.floatValue)
90
93
case (nme.UNARY_- , DoubleTag ) => Constant (- x.doubleValue)
91
94
95
+ case (nme.toByte , _ ) if x.isNumeric => Constant (x.byteValue)
96
+ case (nme.toChar , _ ) if x.isNumeric => Constant (x.charValue)
97
+ case (nme.toShort , _ ) if x.isNumeric => Constant (x.shortValue)
98
+ case (nme.toInt , _ ) if x.isNumeric => Constant (x.intValue)
99
+ case (nme.toLong , _ ) if x.isNumeric => Constant (x.longValue)
100
+ case (nme.toFloat , _ ) if x.isNumeric => Constant (x.floatValue)
101
+ case (nme.toDouble, _ ) if x.isNumeric => Constant (x.doubleValue)
102
+
92
103
case _ => null
93
104
}
94
105
0 commit comments