File tree 4 files changed +26
-3
lines changed
compiler/src/dotty/tools/dotc/parsing
4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ object Parsers {
57
57
val None = 0
58
58
val Quoted = 1
59
59
val Spliced = 1 << 1
60
- val Pattern = 1 << 2
60
+ val QuotedPattern = 1 << 2
61
61
}
62
62
63
63
extension (buf : ListBuffer [Tree ])
@@ -1578,7 +1578,7 @@ object Parsers {
1578
1578
val expr =
1579
1579
if (in.name.length == 1 ) {
1580
1580
in.nextToken()
1581
- val inPattern = (staged & StageKind .Pattern ) != 0
1581
+ val inPattern = (staged & StageKind .QuotedPattern ) != 0
1582
1582
withinStaged(StageKind .Spliced )(if (inPattern) inBraces(pattern()) else stagedBlock())
1583
1583
}
1584
1584
else atSpan(in.offset + 1 ) {
@@ -2276,7 +2276,7 @@ object Parsers {
2276
2276
blockExpr()
2277
2277
case QUOTE =>
2278
2278
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 )) {
2280
2280
Quote {
2281
2281
if (in.token == LBRACKET ) inBrackets(typ())
2282
2282
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
19
19
20
20
def bindQuote (expr : Expr [Any ])(using Quotes ): Expr [Int ] = expr match
21
21
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