@@ -515,12 +515,25 @@ class SpaceEngine(using Context) extends SpaceLogic {
515515 def isPrimToBox (tp : Type , pt : Type ) =
516516 tp.classSymbol.isPrimitiveValueClass && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
517517
518+ /** Adapt types by performing primitive value unboxing or boxing, or numeric constant conversion. #12805
519+ *
520+ * This makes these isSubType cases work like this:
521+ * {{{
522+ * 1 <:< Integer => (<skolem> : Integer) <:< Integer = true
523+ * ONE <:< Int => (<skolem> : Int) <:< Int = true
524+ * Integer <:< (1: Int) => (<skolem> : Int) <:< (1: Int) = false
525+ * }}}
526+ */
527+ def adaptType (tp1 : Type , tp2 : Type ): Type = trace(i " adaptType( $tp1, $tp2) " , show = true ) {
528+ if isPrimToBox(tp1, tp2) then defn.boxedType(tp1).narrow
529+ else if isPrimToBox(tp2, tp1) then defn.unboxedType(tp1).narrow
530+ else convertConstantType(tp1, tp2)
531+ }
532+
518533 /** Is `tp1` a subtype of `tp2`? */
519534 def isSubType (tp1 : Type , tp2 : Type ): Boolean = trace(i " $tp1 <:< $tp2" , debug, show = true ) {
520535 if tp1 == constantNullType && ! ctx.explicitNulls then tp2 == constantNullType
521- else
522- isPrimToBox(tp1, tp2) || isPrimToBox(tp2, tp1) ||
523- convertConstantType(tp1, tp2) <:< tp2
536+ else adaptType(tp1, tp2) <:< tp2
524537 }
525538
526539 def isSameUnapply (tp1 : TermRef , tp2 : TermRef ): Boolean =
0 commit comments