Skip to content

Commit a4c971c

Browse files
committed
Fixes to hk comparisons
- Follow aliases in isMatchingApply - Avoid comparing with TypeBounds in compareHkApply - Generalize kind adaption in liftIfHK Previously we only covered EtaExpansion/reduction. Need to generalize this to the case where a type is partially applied. Test case is pos/partialApplications.scala
1 parent d0adacb commit a4c971c

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
578578

579579
def isMatchingApply(tp1: Type): Boolean = tp1 match {
580580
case HKApply(tycon1, args1) =>
581-
tycon1 match {
581+
tycon1.dealias match {
582582
case tycon1: PolyParam =>
583583
(tycon1 == tycon2 ||
584584
canConstrain(tycon1) && tryInstantiate(tycon1, tycon2)) &&
585585
isSubArgs(args1, args2, tparams)
586586
case tycon1: TypeRef =>
587-
tycon2 match {
587+
tycon2.dealias match {
588588
case tycon2: TypeRef if tycon1.symbol == tycon2.symbol =>
589589
isSubType(tycon1.prefix, tycon2.prefix) &&
590590
isSubArgs(args1, args2, tparams)
@@ -685,7 +685,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
685685
canConstrain(param1) && canInstantiate ||
686686
isSubType(bounds(param1).hi.applyIfParameterized(args1), tp2)
687687
case tycon1: TypeProxy =>
688-
isSubType(tycon1.underlying.applyIfParameterized(args1), tp2)
688+
isSubType(tycon1.underlying.bounds.hi.applyIfParameterized(args1), tp2)
689689
case _ =>
690690
false
691691
}
@@ -1327,16 +1327,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
13271327
if (!Config.newHK && tparams1.isEmpty || tparams2.isEmpty) op(tp1, tp2)
13281328
else if (Config.newHK && tparams1.isEmpty)
13291329
if (tparams2.isEmpty) op(tp1, tp2)
1330-
else tp2 match {
1331-
case EtaExpansion(tycon2) if tycon2.symbol.isClass => original(tp1, tycon2) // TODO: Roll isClass into EtaExpansion?
1332-
case _ => mergeConflict(tp1, tp2)
1333-
}
1334-
else if (Config.newHK && tparams2.isEmpty) {
1335-
tp1 match {
1336-
case EtaExpansion(tycon1) if tycon1.symbol.isClass => original(tycon1, tp2)
1337-
case _ => mergeConflict(tp1, tp2)
1338-
}
1339-
}
1330+
else original(tp1, tp2.appliedTo(tp2.typeParams.map(_.memberBoundsAsSeenFrom(tp2))))
1331+
else if (Config.newHK && tparams2.isEmpty)
1332+
original(tp1.appliedTo(tp1.typeParams.map(_.memberBoundsAsSeenFrom(tp1))), tp2)
13401333
else if (!Config.newHK && (tparams1.isEmpty || tparams2.isEmpty)) op(tp1, tp2)
13411334
else if (!Config.newHK && tparams1.length != tparams2.length) mergeConflict(tp1, tp2)
13421335
else if (Config.newHK) {
@@ -1493,7 +1486,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
14931486
case bounds: TypeBounds => i"type bounds $bounds"
14941487
case _ => tp.show
14951488
}
1496-
throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
1489+
if (true) throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
1490+
else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}")
14971491
}
14981492

14991493
/** Merge two lists of names. If names in corresponding positions match, keep them,

0 commit comments

Comments
 (0)