Skip to content

Commit f97461f

Browse files
Fix TreeMap's treatment of patterns
The `IsStatement` test before this commit treated `Typed(Unapply)` nodes as statements, which is not correct since they are patterns. They must pass the `IsUnapply` test and fail `IsStatement` test. However since they do not fail `IsStatement` test, the `transformTree` method of `TreeMap` incorrectly calls `transformStatement` on a `Typed(Unapply)`. This commit makes the `IsStatement` test treat the trees in question correctly.
1 parent 04a68b8 commit f97461f

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
110110

111111
def matchStatement(tree: Tree)(given Context): Option[Statement] = tree match {
112112
case _: PatternTree => None
113-
case tree if tree.isTerm => Some(tree)
113+
case tree if tree.isTerm => matchTerm(tree)
114114
case _ => matchDefinition(tree)
115115
}
116116

@@ -226,6 +226,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
226226
type Term = tpd.Tree
227227

228228
def matchTerm(tree: Tree)(given Context): Option[Term] = tree match {
229+
case _ if matchTree_Unapply(tree).isDefined => None
229230
case _: PatternTree => None
230231
case x: tpd.SeqLiteral => Some(tree)
231232
case _ if tree.isTerm => Some(tree)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.{ given, _ }
2+
3+
inline def mcr(x: => Unit): Unit = ${mcrImpl('x)}
4+
def mcrImpl(x: Expr[Unit])(given ctx: QuoteContext): Expr[Unit] =
5+
import ctx.tasty.{ given, _ }
6+
val tr: Term = x.unseal
7+
object m extends TreeMap
8+
m.transformTerm(tr).seal.cast[Unit]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@main def Test = mcr {
2+
val (a, b) = ???
3+
println(s"Foo bar")
4+
}

0 commit comments

Comments
 (0)