@@ -830,9 +830,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
830
830
* tp1 <:< tp2 using fourthTry (this might instantiate params in tp1)
831
831
* tp1 <:< app2 using isSubType (this might instantiate params in tp2)
832
832
*/
833
- def compareLower (tycon2bounds : TypeBounds , tyconIsTypeRef : Boolean ): Boolean =
833
+ def compareLower (tycon2bounds : TypeBounds , followSuperType : Boolean ): Boolean =
834
834
if ((tycon2bounds.lo `eq` tycon2bounds.hi) && ! tycon2bounds.isInstanceOf [MatchAlias ])
835
- if (tyconIsTypeRef ) recur(tp1, tp2.superType)
835
+ if (followSuperType ) recur(tp1, tp2.superType)
836
836
else isSubApproxHi(tp1, tycon2bounds.lo.applyIfParameterized(args2))
837
837
else
838
838
fallback(tycon2bounds.lo)
@@ -841,13 +841,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
841
841
case param2 : TypeParamRef =>
842
842
isMatchingApply(tp1) ||
843
843
canConstrain(param2) && canInstantiate(param2) ||
844
- compareLower(bounds(param2), tyconIsTypeRef = false )
844
+ compareLower(bounds(param2), followSuperType = false )
845
845
case tycon2 : TypeRef =>
846
846
isMatchingApply(tp1) ||
847
847
defn.isTypelevel_S(tycon2.symbol) && compareS(tp2, tp1, fromBelow = true ) || {
848
848
tycon2.info match {
849
849
case info2 : TypeBounds =>
850
- compareLower(info2, tyconIsTypeRef = true )
850
+ val gbounds2 = ctx.gadt.bounds(tycon2.symbol)
851
+ if (gbounds2 == null ) compareLower(info2, followSuperType = true )
852
+ else compareLower(gbounds2 & info2, followSuperType = false )
851
853
case info2 : ClassInfo =>
852
854
tycon2.name.toString.startsWith(" Tuple" ) &&
853
855
defn.isTupleType(tp2) && isSubType(tp1, tp2.toNestedPairs) ||
@@ -883,8 +885,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
883
885
case tycon1 : TypeRef =>
884
886
val sym = tycon1.symbol
885
887
! sym.isClass && (
886
- defn.isTypelevel_S(sym) && compareS(tp1, tp2, fromBelow = false ) ||
887
- recur(tp1.superType, tp2))
888
+ defn.isTypelevel_S(sym) && compareS(tp1, tp2, fromBelow = false ) || {
889
+ val gbounds1 = ctx.gadt.bounds(tycon1.symbol)
890
+ if (gbounds1 == null ) recur(tp1.superType, tp2)
891
+ else recur((gbounds1.hi & tycon1.info.bounds.hi).applyIfParameterized(args1), tp2)
892
+ })
888
893
case tycon1 : TypeProxy =>
889
894
recur(tp1.superType, tp2)
890
895
case _ =>
0 commit comments