@@ -377,21 +377,22 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
377377 case _ =>
378378 val cls2 = tp2.symbol
379379 if (cls2.isClass) {
380- if (cls2 eq AnyKindClass )
381- return true
382- else if (cls2.typeParams.nonEmpty && tp1.isHK)
383- return recur(tp1, EtaExpansion (cls2.typeRef))
384- else {
380+ if (cls2.typeParams.isEmpty) {
381+ if (cls2 eq AnyKindClass ) return true
382+ if (tp1.isRef(defn.NothingClass )) return true
383+ if (tp1.isHK) return false
385384 val base = tp1.baseType(cls2)
386- if (base.exists) {
387- if (cls2.is(JavaDefined ))
388- // If `cls2` is parameterized, we are seeing a raw type, so we need to compare only the symbol
389- return base.typeSymbol == cls2
390- if (base ne tp1)
391- return isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
392- }
385+ if (base.exists && base.ne(tp1))
386+ return isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
393387 if (cls2 == defn.SingletonClass && tp1.isStable) return true
394388 }
389+ else if (cls2.is(JavaDefined )) {
390+ // If `cls2` is parameterized, we are seeing a raw type, so we need to compare only the symbol
391+ val base = tp1.baseType(cls2)
392+ if (base.typeSymbol == cls2) return true
393+ }
394+ else if (tp1.isHK && ! tp1.isRef(defn.AnyKindClass ))
395+ return recur(tp1, EtaExpansion (cls2.typeRef))
395396 }
396397 fourthTry
397398 }
@@ -487,13 +488,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
487488 isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
488489 finally comparedTypeLambdas = saved
489490 case _ =>
490- if ( tp1.isHK) {
491- val tparams1 = tp1.typeParams
491+ val tparams1 = tp1.typeParams
492+ if ( tparams1.nonEmpty)
492493 return recur(
493494 HKTypeLambda .fromParams(tparams1, tp1.appliedTo(tparams1.map(_.paramRef))),
494- tp2
495- )
496- }
495+ tp2)
497496 else tp2 match {
498497 case EtaExpansion (tycon2) if tycon2.symbol.isClass =>
499498 return recur(tp1, tycon2)
@@ -552,7 +551,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
552551 def compareTypeBounds = tp1 match {
553552 case tp1 @ TypeBounds (lo1, hi1) =>
554553 ((lo2 eq NothingType ) || isSubType(lo2, lo1)) &&
555- ((hi2 eq AnyType ) || (hi2 eq AnyKindType ) || isSubType(hi1, hi2))
554+ ((hi2 eq AnyType ) && ! hi1.isHK || (hi2 eq AnyKindType ) || isSubType(hi1, hi2))
556555 case tp1 : ClassInfo =>
557556 tp2 contains tp1
558557 case _ =>
@@ -1228,8 +1227,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12281227 if (tp1 eq tp2) tp1
12291228 else if (! tp1.exists) tp2
12301229 else if (! tp2.exists) tp1
1231- else if ((tp1 isRef AnyClass ) || (tp1 isRef AnyKindClass ) || (tp2 isRef NothingClass )) tp2
1232- else if ((tp2 isRef AnyClass ) || (tp2 isRef AnyKindClass ) || (tp1 isRef NothingClass )) tp1
1230+ else if ((tp1 isRef AnyClass ) && ! tp2.isHK || (tp1 isRef AnyKindClass ) || (tp2 isRef NothingClass )) tp2
1231+ else if ((tp2 isRef AnyClass ) && ! tp1.isHK || (tp2 isRef AnyKindClass ) || (tp1 isRef NothingClass )) tp1
12331232 else tp2 match { // normalize to disjunctive normal form if possible.
12341233 case OrType (tp21, tp22) =>
12351234 tp1 & tp21 | tp1 & tp22
0 commit comments