Skip to content

Fix #3381: handle case of lub and glb of types with different kinds #3385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1427,12 +1427,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
private def liftIfHK(tp1: Type, tp2: Type, op: (Type, Type) => Type, original: (Type, Type) => Type) = {
val tparams1 = tp1.typeParams
val tparams2 = tp2.typeParams
def applied(tp: Type) = tp.appliedTo(tp.typeParams.map(_.paramInfoAsSeenFrom(tp)))
if (tparams1.isEmpty)
if (tparams2.isEmpty) op(tp1, tp2)
else original(tp1, tp2.appliedTo(tp2.typeParams.map(_.paramInfoAsSeenFrom(tp2))))
else original(tp1, applied(tp2))
else if (tparams2.isEmpty)
original(tp1.appliedTo(tp1.typeParams.map(_.paramInfoAsSeenFrom(tp1))), tp2)
else
original(applied(tp1), tp2)
else if (tparams1.hasSameLengthAs(tparams2))
HKTypeLambda(
paramNames = (HKTypeLambda.syntheticParamNames(tparams1.length), tparams1, tparams2)
.zipped.map((pname, tparam1, tparam2) =>
Expand All @@ -1442,6 +1443,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
tl.integrate(tparams2, tparam2.paramInfoAsSeenFrom(tp2)).bounds),
resultTypeExp = tl =>
original(tp1.appliedTo(tl.paramRefs), tp2.appliedTo(tl.paramRefs)))
else original(applied(tp1), applied(tp2))
}

/** Try to distribute `&` inside type, detect and handle conflicts
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i3381.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case class Tuple2K[X, A[_], B[_]](a: A[X], b: B[X])

object Test {
def f[X](x: Tuple2K[X, Option, [Y] => Tuple2K[Y, Option, Option]]): Any =
x match {
case Tuple2K(_, Tuple2K(_, _)) => ???
}
}