Skip to content

Commit 271f526

Browse files
committed
Handle feature interaction between subtyping or types and hk types
1 parent 249433c commit 271f526

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
324324
case AndType(tp11, tp12) =>
325325
if (tp11.stripTypeVar eq tp12.stripTypeVar) isSubType(tp11, tp2)
326326
else thirdTry(tp1, tp2)
327-
case OrType(tp11, tp12) =>
328-
isSubType(tp11, tp2) && isSubType(tp12, tp2)
327+
case tp1 @ OrType(tp11, tp12) =>
328+
def joinOK = tp2.dealias match {
329+
case tp12: HKApply =>
330+
// If we apply the default algorithm for `A[X] | B[Y] <: C[Z]` where `C` is a
331+
// type parameter, we will instantiate `C` to `A` and then fail when comparing
332+
// with `B[Y]`. To do the right thing, we need to instantiate `C` to the
333+
// common superclass of `A` and `B`.
334+
isSubType(tp1.join, tp2)
335+
case _ =>
336+
false
337+
}
338+
joinOK || isSubType(tp11, tp2) && isSubType(tp12, tp2)
329339
case ErrorType =>
330340
true
331341
case _ =>

0 commit comments

Comments
 (0)