Skip to content

Commit 8ad49d0

Browse files
committed
Detail why not baseType
1 parent ac51876 commit 8ad49d0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,14 @@ object SpaceEngine {
625625
// but end up with A1[<?>] and A2[<?>].
626626
// So we widen (like AppliedType superType does) away
627627
// non-class type constructors.
628+
//
629+
// Can't use `tpOriginal.baseType(cls)` because it causes
630+
// i15893 to return exhaustivity warnings, because instead of:
631+
// <== refineUsingParent(N, class Succ, []) = Succ[<? <: NatT>]
632+
// <== isSub(Succ[<? <: NatT>] <:< Succ[Succ[<?>]]) = true
633+
// we get
634+
// <== refineUsingParent(NatT, class Succ, []) = Succ[NatT]
635+
// <== isSub(Succ[NatT] <:< Succ[Succ[<?>]]) = false
628636
def getAppliedClass(tp: Type): Type = tp match
629637
case tp @ AppliedType(_: HKTypeLambda, _) => tp
630638
case tp @ AppliedType(tycon: TypeRef, _) if tycon.symbol.isClass => tp

tests/warn/i15893.min.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sealed trait NatT
2+
case class Zero() extends NatT
3+
case class Succ[+N <: NatT](n: N) extends NatT
4+
5+
type Mod2[N <: NatT] <: NatT = N match
6+
case Zero => Zero
7+
case Succ[Zero] => Succ[Zero]
8+
case Succ[Succ[predPredN]] => Mod2[predPredN]
9+
10+
def dependentlyTypedMod2[N <: NatT](n: N): Mod2[N] = n match
11+
case Zero(): Zero => Zero() // warn
12+
case Succ(Zero()): Succ[Zero] => Succ(Zero()) // warn
13+
case Succ(Succ(predPredN)): Succ[Succ[?]] => dependentlyTypedMod2(predPredN) // warn

0 commit comments

Comments
 (0)