@@ -23,7 +23,8 @@ object ConstFold:
2323 nme.ADD , nme.SUB , nme.MUL , nme.DIV , nme.MOD )
2424
2525 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)
2728
2829 def Apply [T <: Apply ](tree : T )(using Context ): T =
2930 tree.fun match
@@ -89,6 +90,14 @@ object ConstFold:
8990 case (nme.UNARY_- , FloatTag ) => Constant (- x.floatValue)
9091 case (nme.UNARY_- , DoubleTag ) => Constant (- x.doubleValue)
9192
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+
92101 case _ => null
93102 }
94103
0 commit comments