@@ -165,7 +165,7 @@ trait SpaceLogic {
165
165
}
166
166
167
167
/** Is `a` a subspace of `b`? Equivalent to `a - b == Empty`, but faster */
168
- def isSubspace (a : Space , b : Space )(using Context ): Boolean = trace(s " ${show(a)} < ${show(b)}" , debug) {
168
+ def isSubspace (a : Space , b : Space )(using Context ): Boolean = trace(s " isSubspace( ${show(a)}, ${show(b)}) " , debug) {
169
169
def tryDecompose1 (tp : Type ) = canDecompose(tp) && isSubspace(Or (decompose(tp)), b)
170
170
def tryDecompose2 (tp : Type ) = canDecompose(tp) && isSubspace(a, Or (decompose(tp)))
171
171
@@ -515,15 +515,22 @@ class SpaceEngine(using Context) extends SpaceLogic {
515
515
if converted == null then tp else ConstantType (converted)
516
516
case _ => tp
517
517
518
+ /** Adapt types by performing primitive value boxing. #12805 */
519
+ def maybeBox (tp1 : Type , tp2 : Type ): Type =
520
+ if tp1.classSymbol.isPrimitiveValueClass && ! tp2.classSymbol.isPrimitiveValueClass then
521
+ defn.boxedType(tp1).narrow
522
+ else tp1
523
+
518
524
/** Is `tp1` a subtype of `tp2`? */
519
525
def isSubType (_tp1 : Type , tp2 : Type ): Boolean = {
520
- val tp1 = convertConstantType(_tp1, tp2)
521
- debug.println(TypeComparer .explained(_.isSubType(tp1, tp2)))
526
+ val tp1 = maybeBox( convertConstantType(_tp1, tp2) , tp2)
527
+ // debug.println(TypeComparer.explained(_.isSubType(tp1, tp2)))
522
528
val res = if (ctx.explicitNulls) {
523
529
tp1 <:< tp2
524
530
} else {
525
531
(tp1 != constantNullType || tp2 == constantNullType) && tp1 <:< tp2
526
532
}
533
+ debug.println(i " $tp1 <:< $tp2 = $res" )
527
534
res
528
535
}
529
536
@@ -663,7 +670,6 @@ class SpaceEngine(using Context) extends SpaceLogic {
663
670
parts.map(Typ (_, true ))
664
671
}
665
672
666
-
667
673
/** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
668
674
def canDecompose (tp : Type ): Boolean =
669
675
val res = tp.dealias match
@@ -679,7 +685,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
679
685
|| cls.isAllOf(JavaEnumTrait )
680
686
|| tp.isRef(defn.BooleanClass )
681
687
|| tp.isRef(defn.UnitClass )
682
- debug.println(s " decomposable: ${tp.show} = $res" )
688
+ // debug.println(s"decomposable: ${tp.show} = $res")
683
689
res
684
690
685
691
/** Show friendly type name with current scope in mind
0 commit comments