Skip to content

Commit 755a81f

Browse files
authored
Merge pull request #8768 from dotty-staging/fix-#8746
Fix #8746: Fix quote matcher block normalization
2 parents c986fdd + bc3e536 commit 755a81f

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ private[quoted] object Matcher {
202202
/** Normalize the tree */
203203
def normalize(tree: Tree): Tree = tree match {
204204
case Block(Nil, expr) => normalize(expr)
205-
case Block(stats1, Block(stats2, expr)) => normalize(Block(stats1 ::: stats2, expr))
205+
case Block(stats1, Block(stats2, expr)) =>
206+
expr match
207+
case _: Closure => tree
208+
case _ => normalize(Block(stats1 ::: stats2, expr))
206209
case Inlined(_, Nil, expr) => normalize(expr)
207210
case _ => tree
208211
}

tests/run/i8746/Macro_1.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
inline def mac(): String = ${ macImpl() }
5+
def macImpl()(using qctx: QuoteContext): Expr[String] =
6+
'{(x: String) => "anything"} match
7+
case '{ (in: String) => ($out: $tpe2) } => Expr(out.toString)
8+
case _ => ???
9+
10+
}

tests/run/i8746/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Macro._
2+
3+
@main def Test() = { // hello
4+
mac()
5+
}

tests/run/i8746b/Macro_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import scala.quoted._
3+
4+
object Macro {
5+
inline def mac(inline tree: Any): String = ${ macImpl('tree) }
6+
def macImpl(tree: Expr[Any])(using qctx: QuoteContext): Expr[String] = {
7+
tree match {
8+
case '{ ($in: $tpe1) => ($out: $tpe2) } => Expr(out.toString)
9+
case _ => Expr("not matched")
10+
}
11+
}
12+
}

tests/run/i8746b/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Macro._
2+
3+
import Macro._
4+
5+
@main def Test() = { //hello
6+
mac((x: String) => "anything")
7+
}

0 commit comments

Comments
 (0)