@@ -4206,14 +4206,14 @@ object Types {
4206
4206
4207
4207
def tryCompiletimeConstantFold (using Context ): Type = tycon match {
4208
4208
case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
4209
- extension (tp : Type ) def fixForEvaluation : Type =
4209
+ extension (tp : Type ) def fixForEvaluation : Type =
4210
4210
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
4217
4217
case tp => tp
4218
4218
}
4219
4219
@@ -4261,43 +4261,43 @@ object Types {
4261
4261
defn.CompiletimeOpsStringModuleClass
4262
4262
)
4263
4263
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
4271
4271
case ConstantType (_) => Some (true )
4272
- // currently not a concrete known type
4272
+ // currently not a concrete known type
4273
4273
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) =>
4280
4280
val argsConst = applied.args.map(isConst)
4281
4281
if (argsConst.exists(_.isEmpty)) None
4282
4282
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
4284
4284
case _ => Some (false )
4285
4285
}
4286
4286
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.
4290
4290
assert(args.length == expectedNum, s " Type operation expects $expectedNum arguments but found ${args.length}" )
4291
4291
4292
4292
def natValue (tp : Type ): Option [Int ] = intValue(tp).filter(n => n >= 0 && n < Int .MaxValue )
4293
4293
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 =
4297
4297
val result = try {
4298
4298
op
4299
4299
} catch {
4300
- case e : Throwable =>
4300
+ case e : Throwable =>
4301
4301
throw new TypeError (e.getMessage)
4302
4302
}
4303
4303
ConstantType (Constant (result))
@@ -4344,7 +4344,7 @@ object Types {
4344
4344
} else if (owner == defn.CompiletimeOpsIntModuleClass ) name match {
4345
4345
case tpnme.Abs => constantFold1(intValue, _.abs)
4346
4346
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
4348
4348
case tpnme.ToString => constantFold1(intValue, _.toString)
4349
4349
case tpnme.Plus => constantFold2(intValue, _ + _)
4350
4350
case tpnme.Minus => constantFold2(intValue, _ - _)
0 commit comments