Skip to content

Fix #8746: Fix quote matcher block normalization #8768

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
Apr 22, 2020
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
5 changes: 4 additions & 1 deletion library/src/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ private[quoted] object Matcher {
/** Normalize the tree */
def normalize(tree: Tree): Tree = tree match {
case Block(Nil, expr) => normalize(expr)
case Block(stats1, Block(stats2, expr)) => normalize(Block(stats1 ::: stats2, expr))
case Block(stats1, Block(stats2, expr)) =>
expr match
case _: Closure => tree
case _ => normalize(Block(stats1 ::: stats2, expr))
case Inlined(_, Nil, expr) => normalize(expr)
case _ => tree
}
Expand Down
10 changes: 10 additions & 0 deletions tests/run/i8746/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted._

object Macro {
inline def mac(): String = ${ macImpl() }
def macImpl()(using qctx: QuoteContext): Expr[String] =
'{(x: String) => "anything"} match
case '{ (in: String) => ($out: $tpe2) } => Expr(out.toString)
case _ => ???

}
5 changes: 5 additions & 0 deletions tests/run/i8746/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Macro._

@main def Test() = { // hello
mac()
}
12 changes: 12 additions & 0 deletions tests/run/i8746b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import scala.quoted._

object Macro {
inline def mac(inline tree: Any): String = ${ macImpl('tree) }
def macImpl(tree: Expr[Any])(using qctx: QuoteContext): Expr[String] = {
tree match {
case '{ ($in: $tpe1) => ($out: $tpe2) } => Expr(out.toString)
case _ => Expr("not matched")
}
}
}
7 changes: 7 additions & 0 deletions tests/run/i8746b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Macro._

import Macro._

@main def Test() = { //hello
mac((x: String) => "anything")
}