Skip to content

Commit af46cd8

Browse files
committed
Don't force BoxedUnitType when forcing UnitType
Otherwise we might end up trying to initialize UnitType recursively, which happens to work with the current implementation of non-volatile lazy vals, but won't work after the next commit.
1 parent fe749ea commit af46cd8

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ class Definitions {
470470
def ArrayModule(implicit ctx: Context): ClassSymbol = ArrayModuleType.symbol.moduleClass.asClass
471471

472472

473-
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
473+
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
474474
def UnitClass(implicit ctx: Context): ClassSymbol = UnitType.symbol.asClass
475475
def UnitModuleClass(implicit ctx: Context): Symbol = UnitType.symbol.asClass.linkedClass
476-
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
476+
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
477477
def BooleanClass(implicit ctx: Context): ClassSymbol = BooleanType.symbol.asClass
478478
lazy val Boolean_notR: TermRef = BooleanClass.requiredMethodRef(nme.UNARY_!)
479479
def Boolean_! : Symbol = Boolean_notR.symbol
@@ -492,13 +492,13 @@ class Definitions {
492492
})
493493
def Boolean_!= : Symbol = Boolean_neqeqR.symbol
494494

495-
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", BoxedByteType, java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
495+
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
496496
def ByteClass(implicit ctx: Context): ClassSymbol = ByteType.symbol.asClass
497-
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", BoxedShortType, java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
497+
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
498498
def ShortClass(implicit ctx: Context): ClassSymbol = ShortType.symbol.asClass
499-
lazy val CharType: TypeRef = valueTypeRef("scala.Char", BoxedCharType, java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
499+
lazy val CharType: TypeRef = valueTypeRef("scala.Char", java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
500500
def CharClass(implicit ctx: Context): ClassSymbol = CharType.symbol.asClass
501-
lazy val IntType: TypeRef = valueTypeRef("scala.Int", BoxedIntType, java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
501+
lazy val IntType: TypeRef = valueTypeRef("scala.Int", java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
502502
def IntClass(implicit ctx: Context): ClassSymbol = IntType.symbol.asClass
503503
lazy val Int_minusR: TermRef = IntClass.requiredMethodRef(nme.MINUS, List(IntType))
504504
def Int_- : Symbol = Int_minusR.symbol
@@ -514,7 +514,7 @@ class Definitions {
514514
def Int_>= : Symbol = Int_geR.symbol
515515
lazy val Int_leR: TermRef = IntClass.requiredMethodRef(nme.LE, List(IntType))
516516
def Int_<= : Symbol = Int_leR.symbol
517-
lazy val LongType: TypeRef = valueTypeRef("scala.Long", BoxedLongType, java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
517+
lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
518518
def LongClass(implicit ctx: Context): ClassSymbol = LongType.symbol.asClass
519519
lazy val Long_XOR_Long: Symbol = LongType.member(nme.XOR).requiredSymbol("method", nme.XOR, LongType.denot)(
520520
x => (x is Method) && (x.info.firstParamTypes.head isRef defn.LongClass)
@@ -529,9 +529,9 @@ class Definitions {
529529
lazy val Long_divR: TermRef = LongClass.requiredMethodRef(nme.DIV, List(LongType))
530530
def Long_/ : Symbol = Long_divR.symbol
531531

532-
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
532+
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
533533
def FloatClass(implicit ctx: Context): ClassSymbol = FloatType.symbol.asClass
534-
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", BoxedDoubleType, java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
534+
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
535535
def DoubleClass(implicit ctx: Context): ClassSymbol = DoubleType.symbol.asClass
536536

537537
lazy val BoxedUnitType: TypeRef = ctx.requiredClassRef("scala.runtime.BoxedUnit")
@@ -1361,23 +1361,23 @@ class Definitions {
13611361

13621362
private lazy val ScalaNumericValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypeList.toSet
13631363
private lazy val ScalaValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypes + UnitType + BooleanType
1364-
private lazy val ScalaBoxedTypes = ScalaValueTypes map (t => boxedTypes(t.name))
13651364

13661365
val ScalaNumericValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaNumericValueTypes.map(_.symbol))
13671366
val ScalaValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaValueTypes.map(_.symbol))
1368-
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaBoxedTypes.map(_.symbol))
13691367

1370-
private val boxedTypes = mutable.Map[TypeName, TypeRef]()
1368+
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx =>
1369+
Set(BoxedByteClass, BoxedShortClass, BoxedCharClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass, BoxedUnitClass, BoxedBooleanClass)
1370+
)
1371+
13711372
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
13721373
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
13731374

13741375
// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
13751376
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
13761377
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
13771378

1378-
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
1379+
private def valueTypeRef(name: String, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
13791380
val vcls = ctx.requiredClassRef(name)
1380-
boxedTypes(vcls.name) = boxed
13811381
valueTypeEnc(vcls.name) = enc
13821382
typeTags(vcls.name) = tag
13831383
// unboxedTypeRef(boxed.name) = vcls
@@ -1387,7 +1387,19 @@ class Definitions {
13871387
}
13881388

13891389
/** The type of the boxed class corresponding to primitive value type `tp`. */
1390-
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp))
1390+
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = {
1391+
val cls = tp.classSymbol
1392+
if (cls eq ByteClass) BoxedByteType
1393+
else if (cls eq ShortClass) BoxedShortType
1394+
else if (cls eq CharClass) BoxedCharType
1395+
else if (cls eq IntClass) BoxedIntType
1396+
else if (cls eq LongClass) BoxedLongType
1397+
else if (cls eq FloatClass) BoxedFloatType
1398+
else if (cls eq DoubleClass) BoxedDoubleType
1399+
else if (cls eq UnitClass) BoxedUnitType
1400+
else if (cls eq BooleanClass) BoxedBooleanType
1401+
else sys.error(s"Not a primitive value type: $tp")
1402+
}
13911403

13921404
/** The JVM tag for `tp` if it's a primitive, `java.lang.Object` otherwise. */
13931405
def typeTag(tp: Type)(implicit ctx: Context): Name = typeTags(scalaClassName(tp))

0 commit comments

Comments
 (0)