@@ -90,29 +90,41 @@ abstract class ConstantFolder {
90
90
else if (foldable) orig setType FoldableConstantType (folded)
91
91
else orig setType LiteralType (folded)
92
92
93
- private def foldUnop (op : Name , x : Constant ): Constant = (op, x.tag) match {
94
- case (nme.UNARY_! , BooleanTag ) => Constant (! x.booleanValue)
95
-
96
- case (nme.UNARY_~ , IntTag ) => Constant (~ x.intValue)
97
- case (nme.UNARY_~ , LongTag ) => Constant (~ x.longValue)
98
-
99
- case (nme.UNARY_+ , IntTag ) => Constant (+ x.intValue)
100
- case (nme.UNARY_+ , LongTag ) => Constant (+ x.longValue)
101
- case (nme.UNARY_+ , FloatTag ) => Constant (+ x.floatValue)
102
- case (nme.UNARY_+ , DoubleTag ) => Constant (+ x.doubleValue)
103
-
104
- case (nme.UNARY_- , IntTag ) => Constant (- x.intValue)
105
- case (nme.UNARY_- , LongTag ) => Constant (- x.longValue)
106
- case (nme.UNARY_- , FloatTag ) => Constant (- x.floatValue)
107
- case (nme.UNARY_- , DoubleTag ) => Constant (- x.doubleValue)
108
-
109
- case (nme.toChar , _) if x.isNumeric => Constant (x.charValue)
110
- case (nme.toInt , _) if x.isNumeric => Constant (x.intValue)
111
- case (nme.toLong , _) if x.isNumeric => Constant (x.longValue)
112
- case (nme.toFloat , _) if x.isNumeric => Constant (x.floatValue)
113
- case (nme.toDouble, _) if x.isNumeric => Constant (x.doubleValue)
114
-
115
- case _ => null
93
+ private def foldUnop (op : Name , x : Constant ): Constant = {
94
+ val N = nme
95
+ import N ._
96
+ val value : Any = op match {
97
+ case UNARY_! => if (x.tag == BooleanTag ) ! x.booleanValue else null
98
+ case UNARY_~ => x.tag match {
99
+ case IntTag => ~ x.intValue
100
+ case LongTag => ~ x.longValue
101
+ case _ => null
102
+ }
103
+ case UNARY_+ => x.tag match {
104
+ case IntTag => + x.intValue
105
+ case LongTag => + x.longValue
106
+ case FloatTag => + x.floatValue
107
+ case DoubleTag => + x.doubleValue
108
+ case _ => null
109
+ }
110
+ case UNARY_- => x.tag match {
111
+ case IntTag => - x.intValue
112
+ case LongTag => - x.longValue
113
+ case FloatTag => - x.floatValue
114
+ case DoubleTag => - x.doubleValue
115
+ case _ => null
116
+ }
117
+ case _ if x.isNumeric => op match {
118
+ case `toChar` => x.charValue
119
+ case `toInt` => x.intValue
120
+ case `toLong` => x.longValue
121
+ case `toFloat` => x.floatValue
122
+ case `toDouble` => x.doubleValue
123
+ case _ => null
124
+ }
125
+ case _ => null
126
+ }
127
+ if (value != null ) Constant (value) else null
116
128
}
117
129
118
130
/** These are local helpers to keep foldBinop from overly taxing the
0 commit comments