Skip to content

Commit

Permalink
PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
adampauls committed Jan 17, 2022
1 parent b0840a6 commit 2a216a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object Parsers {
val None = 0
val Quoted = 1
val Spliced = 1 << 1
val Pattern = 1 << 2
val QuotedPattern = 1 << 2
}

extension (buf: ListBuffer[Tree])
Expand Down Expand Up @@ -1578,7 +1578,7 @@ object Parsers {
val expr =
if (in.name.length == 1) {
in.nextToken()
val inPattern = (staged & StageKind.Pattern) != 0
val inPattern = (staged & StageKind.QuotedPattern) != 0
withinStaged(StageKind.Spliced)(if (inPattern) inBraces(pattern()) else stagedBlock())
}
else atSpan(in.offset + 1) {
Expand Down Expand Up @@ -2276,7 +2276,7 @@ object Parsers {
blockExpr()
case QUOTE =>
atSpan(in.skipToken()) {
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.Pattern else 0)) {
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.QuotedPattern else 0)) {
Quote {
if (in.token == LBRACKET) inBrackets(typ())
else stagedBlock()
Expand Down
17 changes: 17 additions & 0 deletions tests/pos-macros/splice-pat/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import scala.quoted.*

object Macro {
object MyMatcher {
def unapply(expr: Expr[Any])(using Quotes): Option[Expr[Int]] = expr match {
case '{ (${a}: Int) + (${_}: Int) } => Some(a)
case _ => None
}
}

def foo(x: Int): Int = x - 1

def impl(expr: Expr[Any])(using Quotes): Expr[(Int, Int)] = expr match
case '{foo(${bound@MyMatcher(x)})}=> '{($bound, $x)}

inline def macr(inline x: Int): (Int, Int) = ${impl('x)}
}
3 changes: 3 additions & 0 deletions tests/pos-macros/splice-pat/Test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
assert(Macro.macr(Macro.foo(1 + 2)) == (3, 1))
}
3 changes: 3 additions & 0 deletions tests/pos/splice-pat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ def twoLevel(expr: Expr[Any])(using Quotes): Expr[Int] = expr match

def bindQuote(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
case '{ foo(${y@'{bar($_)}})} => y

def noop(expr: Expr[Any])(using Quotes): Expr[Int] = expr match
case '{ bar(${ '{ $y } }) } => y

0 comments on commit 2a216a2

Please sign in to comment.