@@ -3636,41 +3636,49 @@ object Types {
36363636 } yield ConstantType (Constant (op(a, b)))
36373637
36383638 trace(i " compiletime constant fold $this" , typr, show = true ) {
3639- val constantType = if (args.length == 1 ) tycon.symbol.name match {
3640- case tpnme.S => constantFold1(natValue, _ + 1 )
3641- case tpnme.Abs => constantFold1(intValue, _.abs)
3642- case tpnme.Negate => constantFold1(intValue, x => - x)
3643- case tpnme.Not => constantFold1(boolValue, x => ! x)
3644- case tpnme.ToString => constantFold1(intValue, _.toString)
3645- case _ => None
3646- } else if (args.length == 2 ) tycon.symbol.name match {
3647- case tpnme.Equals => constantFold2(constValue, _ == _)
3648- case tpnme.NotEquals => constantFold2(constValue, _ != _)
3649- case tpnme.Plus if tycon.symbol.owner == defn.CompiletimeOpsPackageObjectInt .moduleClass =>
3650- constantFold2(intValue, _ + _)
3651- case tpnme.Plus if tycon.symbol.owner == defn.CompiletimeOpsPackageObjectString .moduleClass =>
3652- constantFold2(stringValue, _ + _)
3653- case tpnme.Minus => constantFold2(intValue, _ - _)
3654- case tpnme.Times => constantFold2(intValue, _ * _)
3655- case tpnme.Div => constantFold2(intValue, {
3656- case (_, 0 ) => throw new TypeError (" Division by 0" )
3657- case (a, b) => a / b
3658- })
3659- case tpnme.Mod => constantFold2(intValue, {
3660- case (_, 0 ) => throw new TypeError (" Modulo by 0" )
3661- case (a, b) => a % b
3662- })
3663- case tpnme.Lt => constantFold2(intValue, _ < _)
3664- case tpnme.Gt => constantFold2(intValue, _ > _)
3665- case tpnme.Ge => constantFold2(intValue, _ >= _)
3666- case tpnme.Le => constantFold2(intValue, _ <= _)
3667- case tpnme.Min => constantFold2(intValue, _ min _)
3668- case tpnme.Max => constantFold2(intValue, _ max _)
3669- case tpnme.And => constantFold2(boolValue, _ && _)
3670- case tpnme.Or => constantFold2(boolValue, _ || _)
3671- case tpnme.Xor => constantFold2(boolValue, _ ^ _)
3672- case _ => None
3673- } else None
3639+ val name = tycon.symbol.name
3640+ val owner = tycon.symbol.owner
3641+ val nArgs = args.length
3642+ val constantType =
3643+ if (owner == defn.CompiletimePackageObject .moduleClass) name match {
3644+ case tpnme.S if nArgs == 1 => constantFold1(natValue, _ + 1 )
3645+ case _ => None
3646+ } else if (owner == defn.CompiletimeOpsPackageObject .moduleClass) name match {
3647+ case tpnme.Equals if nArgs == 2 => constantFold2(constValue, _ == _)
3648+ case tpnme.NotEquals if nArgs == 2 => constantFold2(constValue, _ != _)
3649+ case _ => None
3650+ } else if (owner == defn.CompiletimeOpsPackageObjectInt .moduleClass) name match {
3651+ case tpnme.Abs if nArgs == 1 => constantFold1(intValue, _.abs)
3652+ case tpnme.Negate if nArgs == 1 => constantFold1(intValue, x => - x)
3653+ case tpnme.ToString if nArgs == 1 => constantFold1(intValue, _.toString)
3654+ case tpnme.Plus if nArgs == 2 => constantFold2(intValue, _ + _)
3655+ case tpnme.Minus if nArgs == 2 => constantFold2(intValue, _ - _)
3656+ case tpnme.Times if nArgs == 2 => constantFold2(intValue, _ * _)
3657+ case tpnme.Div if nArgs == 2 => constantFold2(intValue, {
3658+ case (_, 0 ) => throw new TypeError (" Division by 0" )
3659+ case (a, b) => a / b
3660+ })
3661+ case tpnme.Mod if nArgs == 2 => constantFold2(intValue, {
3662+ case (_, 0 ) => throw new TypeError (" Modulo by 0" )
3663+ case (a, b) => a % b
3664+ })
3665+ case tpnme.Lt if nArgs == 2 => constantFold2(intValue, _ < _)
3666+ case tpnme.Gt if nArgs == 2 => constantFold2(intValue, _ > _)
3667+ case tpnme.Ge if nArgs == 2 => constantFold2(intValue, _ >= _)
3668+ case tpnme.Le if nArgs == 2 => constantFold2(intValue, _ <= _)
3669+ case tpnme.Min if nArgs == 2 => constantFold2(intValue, _ min _)
3670+ case tpnme.Max if nArgs == 2 => constantFold2(intValue, _ max _)
3671+ case _ => None
3672+ } else if (owner == defn.CompiletimeOpsPackageObjectString .moduleClass) name match {
3673+ case tpnme.Plus if nArgs == 2 => constantFold2(stringValue, _ + _)
3674+ case _ => None
3675+ } else if (owner == defn.CompiletimeOpsPackageObjectBoolean .moduleClass) name match {
3676+ case tpnme.Not if nArgs == 1 => constantFold1(boolValue, x => ! x)
3677+ case tpnme.And if nArgs == 2 => constantFold2(boolValue, _ && _)
3678+ case tpnme.Or if nArgs == 2 => constantFold2(boolValue, _ || _)
3679+ case tpnme.Xor if nArgs == 2 => constantFold2(boolValue, _ ^ _)
3680+ case _ => None
3681+ } else None
36743682
36753683 constantType.getOrElse(NoType )
36763684 }
0 commit comments