Skip to content

Commit 96afd7a

Browse files
committed
Avoid spurious val binding in quote pattern
Fixes #19947
1 parent 4859415 commit 96afd7a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,8 +3003,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30033003
/** Translate infix operation expression `l op r` to
30043004
*
30053005
* l.op(r) if `op` is left-associative
3006-
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure
3007-
* r.op(l) if `op` is right-associative call-by-name or `l` is pure
3006+
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure, and not in a quote pattern
3007+
* r.op(l) if `op` is right-associative call-by-name, or `l` is pure, or in a quote pattern
30083008
*
30093009
* Translate infix type `l op r` to `op[l, r]`
30103010
* Translate infix pattern `l op r` to `op(l, r)`
@@ -3021,7 +3021,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30213021
typedUnApply(cpy.Apply(tree)(op, l :: r :: Nil), pt)
30223022
else {
30233023
val app = typedApply(desugar.binop(l, op, r), pt)
3024-
if op.name.isRightAssocOperatorName then
3024+
if op.name.isRightAssocOperatorName && !ctx.mode.is(Mode.QuotedExprPattern) then
30253025
val defs = new mutable.ListBuffer[Tree]
30263026
def lift(app: Tree): Tree = (app: @unchecked) match
30273027
case Apply(fn, args) =>

tests/pos-macros/i19947/Macro_1.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted.*
2+
3+
inline def expandMacro(inline from: Tuple): Any =
4+
${ expandMacroImpl }
5+
6+
def expandMacroImpl(using Quotes): Expr[?] =
7+
'{ 1 *: EmptyTuple } match
8+
case '{ ($hd: Int) *: ($tl: Tuple) } => '{ ??? }
9+
case x => throw new MatchError(x.show)

tests/pos-macros/i19947/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Any = expandMacro

0 commit comments

Comments
 (0)