Skip to content

Keep correct kind when preparing constraint in stripParams #14761

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 2 commits into from
Mar 24, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
NoType
case tp: TypeBounds =>
val lo1 = stripParams(tp.lo, todos, !isUpper).orElse(defn.NothingType)
val hi1 = stripParams(tp.hi, todos, isUpper).orElse(defn.AnyKindType)
val hi1 = stripParams(tp.hi, todos, isUpper).orElse(tp.topType)
tp.derivedTypeBounds(lo1, hi1)
case tp: AndType if isUpper =>
val tp1 = stripParams(tp.tp1, todos, isUpper)
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ class TypeApplications(val self: Type) extends AnyVal {
(alias ne self) && alias.hasSimpleKind
}

/** The top type with the same kind as `self`. */
/** The top type with the same kind as `self`. This is largest type capturing
* the parameter shape of a type without looking at precise bounds.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, topType does keep around precise bounds (e.g., [X <: Int] =>> Any), though it could be tweaked to map the bounds themselves to topType if needed.

* - The top-type of simple-kinded types is Any
* - A kind like (* -> *) -> * is represented by the top type [X1 <: [X2] =>> Any] =>> Any
*/
def topType(using Context): Type =
if self.hasSimpleKind then
defn.AnyType
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i14760.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum SUB[-A, +B]:
case Refl[X]() extends SUB[X, X]

def foo[C, A >: C <: C, B](e: SUB[B, A]) = e match
case SUB.Refl() =>