@@ -56,7 +56,8 @@ object Parsers {
5656 object StageKind {
5757 val None = 0
5858 val Quoted = 1
59- val Spliced = 2
59+ val Spliced = 1 << 1
60+ val QuotedPattern = 1 << 2
6061 }
6162
6263 extension (buf : ListBuffer [Tree ])
@@ -1566,15 +1567,19 @@ object Parsers {
15661567 /** The block in a quote or splice */
15671568 def stagedBlock () = inBraces(block(simplify = true ))
15681569
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
15711575 */
15721576 def splice (isType : Boolean ): Tree =
15731577 atSpan(in.offset) {
15741578 val expr =
15751579 if (in.name.length == 1 ) {
15761580 in.nextToken()
1577- withinStaged(StageKind .Spliced )(stagedBlock())
1581+ val inPattern = (staged & StageKind .QuotedPattern ) != 0
1582+ withinStaged(StageKind .Spliced )(if (inPattern) inBraces(pattern()) else stagedBlock())
15781583 }
15791584 else atSpan(in.offset + 1 ) {
15801585 val id = Ident (in.name.drop(1 ))
@@ -2271,7 +2276,7 @@ object Parsers {
22712276 blockExpr()
22722277 case QUOTE =>
22732278 atSpan(in.skipToken()) {
2274- withinStaged(StageKind .Quoted ) {
2279+ withinStaged(StageKind .Quoted | ( if (location.inPattern) StageKind . QuotedPattern else 0 ) ) {
22752280 Quote {
22762281 if (in.token == LBRACKET ) inBrackets(typ())
22772282 else stagedBlock()
@@ -2714,7 +2719,7 @@ object Parsers {
27142719 case LPAREN =>
27152720 atSpan(in.offset) { makeTupleOrParens(inParens(patternsOpt())) }
27162721 case QUOTE =>
2717- simpleExpr(Location .ElseWhere )
2722+ simpleExpr(Location .InPattern )
27182723 case XMLSTART =>
27192724 xmlLiteralPattern()
27202725 case GIVEN =>
0 commit comments