Skip to content

Commit 07e4968

Browse files
Merge pull request #3385 from dotty-staging/fix-#3381
Fix #3381: handle case of lub and glb of types with different kinds
2 parents 863d1a3 + afdc2d3 commit 07e4968

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,12 +1427,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
14271427
private def liftIfHK(tp1: Type, tp2: Type, op: (Type, Type) => Type, original: (Type, Type) => Type) = {
14281428
val tparams1 = tp1.typeParams
14291429
val tparams2 = tp2.typeParams
1430+
def applied(tp: Type) = tp.appliedTo(tp.typeParams.map(_.paramInfoAsSeenFrom(tp)))
14301431
if (tparams1.isEmpty)
14311432
if (tparams2.isEmpty) op(tp1, tp2)
1432-
else original(tp1, tp2.appliedTo(tp2.typeParams.map(_.paramInfoAsSeenFrom(tp2))))
1433+
else original(tp1, applied(tp2))
14331434
else if (tparams2.isEmpty)
1434-
original(tp1.appliedTo(tp1.typeParams.map(_.paramInfoAsSeenFrom(tp1))), tp2)
1435-
else
1435+
original(applied(tp1), tp2)
1436+
else if (tparams1.hasSameLengthAs(tparams2))
14361437
HKTypeLambda(
14371438
paramNames = (HKTypeLambda.syntheticParamNames(tparams1.length), tparams1, tparams2)
14381439
.zipped.map((pname, tparam1, tparam2) =>
@@ -1442,6 +1443,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
14421443
tl.integrate(tparams2, tparam2.paramInfoAsSeenFrom(tp2)).bounds),
14431444
resultTypeExp = tl =>
14441445
original(tp1.appliedTo(tl.paramRefs), tp2.appliedTo(tl.paramRefs)))
1446+
else original(applied(tp1), applied(tp2))
14451447
}
14461448

14471449
/** Try to distribute `&` inside type, detect and handle conflicts

tests/pos/i3381.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
case class Tuple2K[X, A[_], B[_]](a: A[X], b: B[X])
2+
3+
object Test {
4+
def f[X](x: Tuple2K[X, Option, [Y] => Tuple2K[Y, Option, Option]]): Any =
5+
x match {
6+
case Tuple2K(_, Tuple2K(_, _)) => ???
7+
}
8+
}

0 commit comments

Comments
 (0)