Skip to content

Commit f54af21

Browse files
Merge pull request #6465 from dotty-staging/fix-#6435
Fix #6435: Collect variables in quoted patterns
2 parents 5cf22ca + a36d90f commit f54af21

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,14 @@ object desugar {
15501550
trees foreach collect
15511551
case Block(Nil, expr) =>
15521552
collect(expr)
1553+
case Quote(expr) =>
1554+
new TreeTraverser {
1555+
def traverse(tree: untpd.Tree)(implicit ctx: Context): Unit = tree match {
1556+
case Splice(expr) => collect(expr)
1557+
case TypSplice(expr) => collect(expr)
1558+
case _ => traverseChildren(tree)
1559+
}
1560+
}.traverse(expr)
15531561
case _ =>
15541562
}
15551563
collect(tree)

tests/pos/i6435.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo {
2+
import scala.quoted._
3+
import scala.quoted.matching._
4+
def f(sc: quoted.Expr[StringContext]) given tasty.Reflection: Unit = {
5+
6+
val '{ StringContext(${parts}: _*) } = sc
7+
val ps0: Expr[Seq[String]] = parts
8+
9+
val '{ StringContext(${ExprSeq(parts2)}: _*) } = sc
10+
val ps: Seq[Expr[String]] = parts2
11+
}
12+
}

0 commit comments

Comments
 (0)