@@ -512,41 +512,13 @@ class SpaceEngine(using Context) extends SpaceLogic {
512
512
if converted == null then tp else ConstantType (converted)
513
513
case _ => tp
514
514
515
- private lazy val defn = ctx.definitions
516
- private lazy val ByteClass = defn.ByteClass
517
- private lazy val ShortClass = defn.ShortClass
518
- private lazy val CharClass = defn.CharClass
519
- private lazy val IntClass = defn.IntClass
520
- private lazy val LongClass = defn.LongClass
521
- private lazy val FloatClass = defn.FloatClass
522
- private lazy val DoubleClass = defn.DoubleClass
523
- private lazy val UnitClass = defn.UnitClass
524
- private lazy val BooleanClass = defn.BooleanClass
525
-
526
- /** Adapt types by performing primitive value unboxing or boxing, or numeric constant conversion. #12805 */
527
- def adaptType (tp1 : Type , tp2 : Type ): Type = trace(i " adaptType( $tp1, $tp2) " , show = true )((tp1.classSymbol, tp2.classSymbol) match {
528
- case ( ByteClass , defn.BoxedByteClass ) => defn.BoxedByteClass .typeRef.narrow
529
- case ( ShortClass , defn.BoxedShortClass ) => defn.BoxedShortClass .typeRef.narrow
530
- case ( CharClass , defn.BoxedCharClass ) => defn.BoxedCharClass .typeRef.narrow
531
- case ( IntClass , defn.BoxedIntClass ) => defn.BoxedIntClass .typeRef.narrow // 1 <:< Integer => (<skolem> : Integer) <:< Integer = true
532
- case ( LongClass , defn.BoxedLongClass ) => defn.BoxedLongClass .typeRef.narrow
533
- case ( FloatClass , defn.BoxedFloatClass ) => defn.BoxedFloatClass .typeRef.narrow
534
- case ( DoubleClass , defn.BoxedDoubleClass ) => defn.BoxedDoubleClass .typeRef.narrow
535
- case ( UnitClass , defn.BoxedUnitClass ) => defn.BoxedUnitClass .typeRef.narrow
536
- case (BooleanClass , defn.BoxedBooleanClass ) => defn.BoxedBooleanClass .typeRef.narrow
537
-
538
- case ( defn.BoxedByteClass , ByteClass ) => defn.ByteType .narrow
539
- case ( defn.BoxedShortClass , ShortClass ) => defn.ShortType .narrow
540
- case ( defn.BoxedCharClass , CharClass ) => defn.CharType .narrow
541
- case ( defn.BoxedIntClass , IntClass ) => defn.IntType .narrow // ONE <:< Int => (<skolem> : Int) <:< Int = true
542
- case ( defn.BoxedLongClass , LongClass ) => defn.LongType .narrow
543
- case ( defn.BoxedFloatClass , FloatClass ) => defn.FloatType .narrow
544
- case ( defn.BoxedDoubleClass , DoubleClass ) => defn.DoubleType .narrow
545
- case ( defn.BoxedUnitClass , UnitClass ) => defn.UnitType .narrow
546
- case (defn.BoxedBooleanClass , BooleanClass ) => defn.BooleanType .narrow
547
-
548
- case _ => convertConstantType(tp1, tp2)
549
- })
515
+ def adaptType (tp1 : Type , tp2 : Type ): Type = trace(i " adaptType( $tp1, $tp2) " , show = true ) {
516
+ def isPrimToBox (tp : Type , pt : Type ) =
517
+ tp.classSymbol.isPrimitiveValueClass && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
518
+ if isPrimToBox(tp1, tp2) then defn.boxedType(tp1).narrow // 1 <:< Integer => (<skolem> : Integer) <:< Integer = true
519
+ else if isPrimToBox(tp2, tp1) then defn.unboxedType(tp1).narrow // ONE <:< Int => (<skolem> : Int) <:< Int = true
520
+ else convertConstantType(tp1, tp2)
521
+ }
550
522
551
523
/** Is `tp1` a subtype of `tp2`? */
552
524
def isSubType (tp1 : Type , tp2 : Type ): Boolean = trace(i " $tp1 <:< $tp2" , debug, show = true ) {
0 commit comments