Skip to content

Commit eae8920

Browse files
committed
Keep correct kind when preparing constraint in stripParams
Fixes #14760
1 parent e64fc49 commit eae8920

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
248248
NoType
249249
case tp: TypeBounds =>
250250
val lo1 = stripParams(tp.lo, todos, !isUpper).orElse(defn.NothingType)
251-
val hi1 = stripParams(tp.hi, todos, isUpper).orElse(defn.AnyKindType)
251+
val hi1 = stripParams(tp.hi, todos, isUpper).orElse(tp.kind)
252252
tp.derivedTypeBounds(lo1, hi1)
253253
case tp: AndType if isUpper =>
254254
val tp1 = stripParams(tp.tp1, todos, isUpper)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ class TypeApplications(val self: Type) extends AnyVal {
258258
case _ => NoType
259259
}
260260

261+
/** The kind of a type is the largest type capturing the parameter shape
262+
* of a type without looking at precise bounds.
263+
* - The kind of single-kinded types is Any
264+
* - A kind like (* -> *) -> * is represented as [X1 <: [X2] =>> Any] =>> Any
265+
*/
266+
def kind(using Context): Type = self.hkResult match
267+
case NoType => defn.AnyType
268+
case self: TypeRef if self.symbol == defn.AnyKindClass => self
269+
case rt =>
270+
HKTypeLambda(
271+
self.typeParams.map(tparam => TypeBounds.upper(tparam.paramInfo.hiBound.kind)),
272+
rt.kind)
273+
261274
/** Do self and other have the same kinds (not counting bounds and variances)?
262275
* Note: An any-kinded type "has the same kind" as any other type.
263276
*/

tests/pos/i14760.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum SUB[-A, +B]:
2+
case Refl[X]() extends SUB[X, X]
3+
4+
def foo[C, A >: C <: C, B](e: SUB[B, A]) = e match
5+
case SUB.Refl() =>

0 commit comments

Comments
 (0)