File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff 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()
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ object Test {
2+ assert(Macro .macr(Macro .foo(1 + 2 )) == (3 , 1 ))
3+ }
Original file line number Diff line number Diff line change @@ -19,3 +19,6 @@ def twoLevel(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
1919
2020def 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
You can’t perform that action at this time.
0 commit comments