Skip to content

Commit d00a7ba

Browse files
Merge pull request #6216 from dotty-staging/fix-#6215
Fix #6215: Keep track of levels inside patterns
2 parents a998f0c + fdbf680 commit d00a7ba

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
108108
val last = enteredSyms
109109
// mark all bindings
110110
new TreeTraverser {
111-
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
112-
markDef(tree)
113-
traverseChildren(tree)
111+
def traverse(tree: Tree)(implicit ctx: Context): Unit = tree match {
112+
case Quoted(t) => traverse(t)(quoteContext)
113+
case Splice(t) => traverse(t)(spliceContext)
114+
case _ =>
115+
markDef(tree)
116+
traverseChildren(tree)
114117
}
115118
}.traverse(pat)
116119
mapOverTree(last)

tests/neg/quotedPatterns-1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
def test(x: quoted.Expr[Int]) given tasty.Reflection = x match {
3+
case '{ val a = '{ println($y) }; 0 } => ??? // error: Not found: y
4+
case _ =>
5+
}
6+
}

tests/neg/quotedPatterns-2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
def test(x: quoted.Expr[Int]) given tasty.Reflection = x match {
3+
case '{ val a = 4; '{ a }; $y } => y // error: access to value a from wrong staging level
4+
case _ =>
5+
}
6+
}

tests/neg/quotedPatterns.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/pos/quotedPatterns.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ object Test {
99
case '{1 + 2} => '{0}
1010
case '{f($y)} => y
1111
case '{g($y, $z)} => '{$y * $z}
12+
case '{ ((a: Int) => 3)($y) } => y
1213
case '{ 1 + ($y: Int)} => y
1314
// currently gives an unreachable case warning
1415
// but only when used in conjunction with the others.

0 commit comments

Comments
 (0)