File tree 1 file changed +12
-2
lines changed
src/dotty/tools/dotc/core 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -324,8 +324,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
324
324
case AndType (tp11, tp12) =>
325
325
if (tp11.stripTypeVar eq tp12.stripTypeVar) isSubType(tp11, tp2)
326
326
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)
329
339
case ErrorType =>
330
340
true
331
341
case _ =>
You can’t perform that action at this time.
0 commit comments