Skip to content

Fix #9533: handle nested TypeParamRef in bounds #10109

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 3 commits into from
Oct 30, 2020
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
41 changes: 22 additions & 19 deletions compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class ProperGadtConstraint private(
case null => null
case tv =>
fullBounds(tv.origin)
.ensuring(containsNoInternalTypes(_))
// .ensuring(containsNoInternalTypes(_))
}

override def bounds(sym: Symbol)(using Context): TypeBounds =
Expand Down Expand Up @@ -223,24 +223,27 @@ final class ProperGadtConstraint private(
override protected def isSub(tp1: Type, tp2: Type)(using Context): Boolean = TypeComparer.isSubType(tp1, tp2)
override protected def isSame(tp1: Type, tp2: Type)(using Context): Boolean = TypeComparer.isSameType(tp1, tp2)

override def nonParamBounds(param: TypeParamRef)(using Context): TypeBounds =
constraint.nonParamBounds(param) match {
case TypeAlias(tpr: TypeParamRef) => TypeAlias(externalize(tpr))
case tb => tb
}

override def fullLowerBound(param: TypeParamRef)(using Context): Type =
constraint.minLower(param).foldLeft(nonParamBounds(param).lo) {
(t, u) => t | externalize(u)
}

override def fullUpperBound(param: TypeParamRef)(using Context): Type =
constraint.minUpper(param).foldLeft(nonParamBounds(param).hi) { (t, u) =>
val eu = externalize(u)
// Any as the upper bound means "no bound", but if F is higher-kinded,
// Any & F = F[_]; this is wrong for us so we need to short-circuit
if t.isAny then eu else t & eu
}
override def nonParamBounds(param: TypeParamRef)(using Context): TypeBounds =
val externalizeMap = new TypeMap {
def apply(tp: Type): Type = tp match {
case tpr: TypeParamRef => externalize(tpr)
case tp => mapOver(tp)
}
}
externalizeMap(constraint.nonParamBounds(param)).bounds

override def fullLowerBound(param: TypeParamRef)(using Context): Type =
constraint.minLower(param).foldLeft(nonParamBounds(param).lo) {
(t, u) => t | externalize(u)
}

override def fullUpperBound(param: TypeParamRef)(using Context): Type =
constraint.minUpper(param).foldLeft(nonParamBounds(param).hi) { (t, u) =>
val eu = externalize(u)
// Any as the upper bound means "no bound", but if F is higher-kinded,
// Any & F = F[_]; this is wrong for us so we need to short-circuit
if t.isAny then eu else t & eu
}

// ---- Private ----------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i9533.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object Test {
sealed trait Base[-X]
case class Child[X]() extends Base[X]

def apply[A, B](r: Base[A with B]): Unit = {
r match {
case Child() => ()
}
}
}