Skip to content

Commit 3e15605

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 3e15605

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
109109
type Statement = tpd.Tree
110110

111111
def matchStatement(tree: Tree)(given Context): Option[Statement] = tree match {
112+
case _ if matchTree_Unapply(tree).isDefined => None
112113
case _: PatternTree => None
113114
case tree if tree.isTerm => Some(tree)
114115
case _ => matchDefinition(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)