Skip to content

Commit 7171f6a

Browse files
Fix TreeMap's transformTerm wrt UnApply
UnApply <: Term however it cannot appear where a term can. Hence we do not transform it from transformTerm and guard against it getting into transformTerm to prevent MatchErrors.
1 parent 4d8dc20 commit 7171f6a

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 _: UnApply => None
229230
case _: PatternTree => None
230231
case x: tpd.SeqLiteral => Some(tree)
231232
case _ if tree.isTerm => Some(tree)

library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ trait TreeUtils
157157
}
158158
}
159159

160-
def transformTerm(tree: Term)(given ctx: Context): Term = {
160+
def transformTerm(tree: Term)(given ctx: Context): Term = if IsTerm.unapply(tree).isEmpty then tree else
161161
tree match {
162162
case Ident(name) =>
163163
tree
@@ -200,7 +200,6 @@ trait TreeUtils
200200
case Inlined(call, bindings, expansion) =>
201201
Inlined.copy(tree)(call, transformSubTrees(bindings), transformTerm(expansion)/*()call.symbol.localContext)*/)
202202
}
203-
}
204203

205204
def transformTypeTree(tree: TypeTree)(given ctx: Context): TypeTree = tree match {
206205
case Inferred() => 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)