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