@@ -56,7 +56,8 @@ object Parsers {
56
56
object StageKind {
57
57
val None = 0
58
58
val Quoted = 1
59
- val Spliced = 2
59
+ val Spliced = 1 << 1
60
+ val Pattern = 1 << 2
60
61
}
61
62
62
63
extension (buf : ListBuffer [Tree ])
@@ -1566,15 +1567,19 @@ object Parsers {
1566
1567
/** The block in a quote or splice */
1567
1568
def stagedBlock () = inBraces(block(simplify = true ))
1568
1569
1569
- /** SimpleEpxr ::= spliceId | ‘$’ ‘{’ Block ‘}’)
1570
- * SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’)
1570
+ /** SimpleExpr ::= spliceId | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1571
+ * SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1572
+ *
1573
+ * SimpleExpr ::= spliceId | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
1574
+ * SimpleType ::= spliceId | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
1571
1575
*/
1572
1576
def splice (isType : Boolean ): Tree =
1573
1577
atSpan(in.offset) {
1574
1578
val expr =
1575
1579
if (in.name.length == 1 ) {
1576
1580
in.nextToken()
1577
- withinStaged(StageKind .Spliced )(stagedBlock())
1581
+ val inPattern = (staged & StageKind .Pattern ) != 0
1582
+ withinStaged(StageKind .Spliced )(if (inPattern) inBraces(pattern()) else stagedBlock())
1578
1583
}
1579
1584
else atSpan(in.offset + 1 ) {
1580
1585
val id = Ident (in.name.drop(1 ))
@@ -2271,7 +2276,7 @@ object Parsers {
2271
2276
blockExpr()
2272
2277
case QUOTE =>
2273
2278
atSpan(in.skipToken()) {
2274
- withinStaged(StageKind .Quoted ) {
2279
+ withinStaged(StageKind .Quoted | ( if (location.inPattern) StageKind . Pattern else 0 ) ) {
2275
2280
Quote {
2276
2281
if (in.token == LBRACKET ) inBrackets(typ())
2277
2282
else stagedBlock()
@@ -2714,7 +2719,7 @@ object Parsers {
2714
2719
case LPAREN =>
2715
2720
atSpan(in.offset) { makeTupleOrParens(inParens(patternsOpt())) }
2716
2721
case QUOTE =>
2717
- simpleExpr(Location .ElseWhere )
2722
+ simpleExpr(Location .InPattern )
2718
2723
case XMLSTART =>
2719
2724
xmlLiteralPattern()
2720
2725
case GIVEN =>
0 commit comments