Skip to content

Commit e04e529

Browse files
committed
fix #3645: handle type alias in child instantiation
1 parent 211cc8f commit e04e529

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
594594

595595
// replace type parameter references with bounds
596596
val typeParamMap = new TypeMap {
597-
def apply(t: Type): Type = t match {
598-
case tp: TypeRef if tp.symbol.is(TypeParam) && tp.underlying.isInstanceOf[TypeBounds] =>
597+
def apply(t: Type): Type = t.dealias match {
598+
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
599599
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
600600
val exposed =
601601
if (variance == 0) newTypeVar(tp.underlying.bounds)

tests/patmat/3543.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20: Pattern Match Exhaustivity: KInt

tests/patmat/i3645.check

Whitespace-only changes.

tests/patmat/i3645.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
object App {
2+
def main(args: Array[String]): Unit = {
3+
trait AgeT {
4+
type T
5+
def subst[F[_]](fa: F[Int]): F[T]
6+
}
7+
8+
type Age = Age.T
9+
10+
val Age: AgeT = new AgeT {
11+
type T = Int
12+
def subst[F[_]](fa: F[Int]): F[T] = fa
13+
}
14+
15+
sealed abstract class K[A]
16+
final case object KAge extends K[Age]
17+
final case object KInt extends K[Int]
18+
19+
val kint: K[Age] = Age.subst[K](KInt)
20+
def get(k: K[Age]): String = k match {
21+
case KAge => "Age"
22+
}
23+
24+
get(kint)
25+
}
26+
}

0 commit comments

Comments
 (0)