Skip to content

Commit

Permalink
Avoid spurious val binding in quote pattern
Browse files Browse the repository at this point in the history
Fixes #19947

[Cherry-picked 96afd7a]
  • Loading branch information
nicolasstucki authored and WojciechMazur committed Jul 3, 2024
1 parent 9b83580 commit 3bc8e26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2935,8 +2935,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
/** Translate infix operation expression `l op r` to
*
* l.op(r) if `op` is left-associative
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure
* r.op(l) if `op` is right-associative call-by-name or `l` is pure
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure, and not in a quote pattern
* r.op(l) if `op` is right-associative call-by-name, or `l` is pure, or in a quote pattern
*
* Translate infix type `l op r` to `op[l, r]`
* Translate infix pattern `l op r` to `op(l, r)`
Expand All @@ -2953,7 +2953,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
typedUnApply(cpy.Apply(tree)(op, l :: r :: Nil), pt)
else {
val app = typedApply(desugar.binop(l, op, r), pt)
if op.name.isRightAssocOperatorName then
if op.name.isRightAssocOperatorName && !ctx.mode.is(Mode.QuotedExprPattern) then
val defs = new mutable.ListBuffer[Tree]
def lift(app: Tree): Tree = (app: @unchecked) match
case Apply(fn, args) =>
Expand Down
9 changes: 9 additions & 0 deletions tests/pos-macros/i19947/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted.*

inline def expandMacro(inline from: Tuple): Any =
${ expandMacroImpl }

def expandMacroImpl(using Quotes): Expr[?] =
'{ 1 *: EmptyTuple } match
case '{ ($hd: Int) *: ($tl: Tuple) } => '{ ??? }
case x => throw new MatchError(x.show)
1 change: 1 addition & 0 deletions tests/pos-macros/i19947/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test: Any = expandMacro

0 comments on commit 3bc8e26

Please sign in to comment.