Skip to content

Fix TreeMap's transformTerm wrt UnApply #7503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend

def matchStatement(tree: Tree)(given Context): Option[Statement] = tree match {
case _: PatternTree => None
case tree if tree.isTerm => Some(tree)
case tree if tree.isTerm => matchTerm(tree)
case _ => matchDefinition(tree)
}

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

def matchTerm(tree: Tree)(given Context): Option[Term] = tree match {
case _ if matchTree_Unapply(tree).isDefined => None
case _: PatternTree => None
case x: tpd.SeqLiteral => Some(tree)
case _ if tree.isTerm => Some(tree)
Expand Down
8 changes: 8 additions & 0 deletions tests/pos-macros/treemap-unapply/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted.{ given, _ }

inline def mcr(x: => Unit): Unit = ${mcrImpl('x)}
def mcrImpl(x: Expr[Unit])(given ctx: QuoteContext): Expr[Unit] =
import ctx.tasty.{ given, _ }
val tr: Term = x.unseal
object m extends TreeMap
m.transformTerm(tr).seal.cast[Unit]
4 changes: 4 additions & 0 deletions tests/pos-macros/treemap-unapply/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@main def Test = mcr {
val (a, b) = ???
println(s"Foo bar")
}