@@ -4206,14 +4206,14 @@ object Types {
42064206
42074207 def tryCompiletimeConstantFold (using Context ): Type = tycon match {
42084208 case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
4209- extension (tp : Type ) def fixForEvaluation : Type =
4209+ extension (tp : Type ) def fixForEvaluation : Type =
42104210 tp.normalized.dealias match {
4211- // enable operations for constant singleton terms. E.g.:
4212- // ```
4213- // final val one = 1
4214- // type Two = one.type + one.type
4215- // ```
4216- case tp : TermRef => tp.underlying
4211+ // enable operations for constant singleton terms. E.g.:
4212+ // ```
4213+ // final val one = 1
4214+ // type Two = one.type + one.type
4215+ // ```
4216+ case tp : TermRef => tp.underlying
42174217 case tp => tp
42184218 }
42194219
@@ -4261,43 +4261,43 @@ object Types {
42614261 defn.CompiletimeOpsStringModuleClass
42624262 )
42634263
4264- // Returns Some(true) if the type is a constant.
4265- // Returns Some(false) if the type is not a constant.
4266- // Returns None if there is not enough information to determine if the type is a constant.
4267- // The type is a constant if it is a constant type or a type operation composition of constant types.
4268- // If we get a type reference for an argument, then the result is not yet known.
4269- def isConst (tp : Type ) : Option [Boolean ] = tp.dealias match {
4270- // known to be constant
4264+ // Returns Some(true) if the type is a constant.
4265+ // Returns Some(false) if the type is not a constant.
4266+ // Returns None if there is not enough information to determine if the type is a constant.
4267+ // The type is a constant if it is a constant type or a type operation composition of constant types.
4268+ // If we get a type reference for an argument, then the result is not yet known.
4269+ def isConst (tp : Type ): Option [Boolean ] = tp.dealias match {
4270+ // known to be constant
42714271 case ConstantType (_) => Some (true )
4272- // currently not a concrete known type
4272+ // currently not a concrete known type
42734273 case TypeRef (NoPrefix ,_) => None
4274- // currently not a concrete known type
4275- case _ : TypeParamRef => None
4276- // constant if the term is constant
4277- case t : TermRef => isConst(t.underlying)
4278- // an operation type => recursively check all argument compositions
4279- case applied : AppliedType if opsSet.contains(applied.typeSymbol.owner) =>
4274+ // currently not a concrete known type
4275+ case _ : TypeParamRef => None
4276+ // constant if the term is constant
4277+ case t : TermRef => isConst(t.underlying)
4278+ // an operation type => recursively check all argument compositions
4279+ case applied : AppliedType if opsSet.contains(applied.typeSymbol.owner) =>
42804280 val argsConst = applied.args.map(isConst)
42814281 if (argsConst.exists(_.isEmpty)) None
42824282 else Some (argsConst.forall(_.get))
4283- // all other types are considered not to be constant
4283+ // all other types are considered not to be constant
42844284 case _ => Some (false )
42854285 }
42864286
4287- def expectArgsNum (expectedNum : Int ) : Unit =
4288- // We can use assert instead of a compiler type error because this error should not
4289- // occur since the type signature of the operation enforces the proper number of args.
4287+ def expectArgsNum (expectedNum : Int ): Unit =
4288+ // We can use assert instead of a compiler type error because this error should not
4289+ // occur since the type signature of the operation enforces the proper number of args.
42904290 assert(args.length == expectedNum, s " Type operation expects $expectedNum arguments but found ${args.length}" )
42914291
42924292 def natValue (tp : Type ): Option [Int ] = intValue(tp).filter(n => n >= 0 && n < Int .MaxValue )
42934293
4294- // Runs the op and returns the result as a constant type.
4295- // If the op throws an exception, then this exception is converted into a type error.
4296- def runConstantOp (op : => Any ): Type =
4294+ // Runs the op and returns the result as a constant type.
4295+ // If the op throws an exception, then this exception is converted into a type error.
4296+ def runConstantOp (op : => Any ): Type =
42974297 val result = try {
42984298 op
42994299 } catch {
4300- case e : Throwable =>
4300+ case e : Throwable =>
43014301 throw new TypeError (e.getMessage)
43024302 }
43034303 ConstantType (Constant (result))
@@ -4344,7 +4344,7 @@ object Types {
43444344 } else if (owner == defn.CompiletimeOpsIntModuleClass ) name match {
43454345 case tpnme.Abs => constantFold1(intValue, _.abs)
43464346 case tpnme.Negate => constantFold1(intValue, x => - x)
4347- // ToString is deprecated for ops.int, and moved to ops.any
4347+ // ToString is deprecated for ops.int, and moved to ops.any
43484348 case tpnme.ToString => constantFold1(intValue, _.toString)
43494349 case tpnme.Plus => constantFold2(intValue, _ + _)
43504350 case tpnme.Minus => constantFold2(intValue, _ - _)
0 commit comments