Skip to content

Commit 898c47d

Browse files
committed
support GADT reasoning on aliases for nested pattern
1 parent e043fdd commit 898c47d

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,15 @@ final class ProperGadtConstraint private(
677677

678678
updateMappings()
679679
updateUnionFind()
680+
myPatternSkolem = null
680681
end supplyPatternPath
681682

682683
override def createPatternSkolem(pat: Type): SkolemType =
683-
myPatternSkolem = SkolemType(pat)
684-
myPatternSkolem.nn
684+
if myPatternSkolem ne null then
685+
SkolemType(pat)
686+
else
687+
myPatternSkolem = SkolemType(pat)
688+
myPatternSkolem.nn
685689
end createPatternSkolem
686690

687691
override def withScrutineePath[T](path: TermRef | Null)(op: => T): T =

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,10 +1754,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17541754
sel.tpe match {
17551755
case p: TermRef =>
17561756
tree.pat match {
1757-
case _: Trees.Typed[_] => p
1758-
case _: Trees.Ident[_] => p
1759-
case _: Trees.Apply[_] => p
1760-
case _ => null
1757+
case _: (Trees.Typed[_] | Trees.Ident[_] | Trees.Apply[_] | Trees.Bind[_]) =>
1758+
p
1759+
case _ =>
1760+
null
17611761
}
17621762
case _ => null
17631763
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Expr { type T }
2+
case class B(b: Int) extends Expr { type T = Int }
3+
case class C(c: Boolean) extends Expr { type T = Boolean }
4+
case class A(a: Expr, b: Expr) extends Expr { type T = (a.T, b.T) }
5+
6+
def foo(e: Expr) = e match
7+
case e1 @ A(b1 @ B(b), c1 @ C(c)) =>
8+
val t1: e1.type = e
9+
val t2: e.type = e1
10+
11+
val t3: b1.type = e // error
12+
val t4: c1.type = e // error

0 commit comments

Comments
 (0)