Skip to content

Commit 9ae3b87

Browse files
committed
PR comments.
1 parent d637cce commit 9ae3b87

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object Parsers {
5757
val None = 0
5858
val Quoted = 1
5959
val Spliced = 1 << 1
60-
val Pattern = 1 << 2
60+
val QuotedPattern = 1 << 2
6161
}
6262

6363
extension (buf: ListBuffer[Tree])
@@ -1578,7 +1578,7 @@ object Parsers {
15781578
val expr =
15791579
if (in.name.length == 1) {
15801580
in.nextToken()
1581-
val inPattern = (staged & StageKind.Pattern) != 0
1581+
val inPattern = (staged & StageKind.QuotedPattern) != 0
15821582
withinStaged(StageKind.Spliced)(if (inPattern) inBraces(pattern()) else stagedBlock())
15831583
}
15841584
else atSpan(in.offset + 1) {
@@ -2276,7 +2276,7 @@ object Parsers {
22762276
blockExpr()
22772277
case QUOTE =>
22782278
atSpan(in.skipToken()) {
2279-
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.Pattern else 0)) {
2279+
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.QuotedPattern else 0)) {
22802280
Quote {
22812281
if (in.token == LBRACKET) inBrackets(typ())
22822282
else stagedBlock()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.quoted.*
2+
3+
object Macro {
4+
object MyMatcher {
5+
def unapply(expr: Expr[Any])(using Quotes): Option[Expr[Int]] = expr match {
6+
case '{ (${a}: Int) + (${_}: Int) } => Some(a)
7+
case _ => None
8+
}
9+
}
10+
11+
def foo(x: Int): Int = x - 1
12+
13+
def impl(expr: Expr[Any])(using Quotes): Expr[(Int, Int)] = expr match
14+
case '{foo(${bound@MyMatcher(x)})}=> '{($bound, $x)}
15+
16+
inline def macr(inline x: Int): (Int, Int) = ${impl('x)}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
assert(Macro.macr(Macro.foo(1 + 2)) == (3, 1))
3+
}

tests/pos/splice-pat.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ def twoLevel(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
1919

2020
def bindQuote(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
2121
case '{ foo(${y@'{bar($_)}})} => y
22+
23+
def noop(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
24+
case '{ bar(${ '{ $y } }) } => y

0 commit comments

Comments
 (0)