Skip to content

Commit 27ecfe2

Browse files
Backport "Avoid spurious val binding in quote pattern" to LTS (#20999)
Backports #19948 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents df98f58 + 484b808 commit 27ecfe2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -2935,8 +2935,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29352935
/** Translate infix operation expression `l op r` to
29362936
*
29372937
* l.op(r) if `op` is left-associative
2938-
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure
2939-
* r.op(l) if `op` is right-associative call-by-name or `l` is pure
2938+
* { val x = l; r.op(x) } if `op` is right-associative call-by-value and `l` is impure, and not in a quote pattern
2939+
* r.op(l) if `op` is right-associative call-by-name, or `l` is pure, or in a quote pattern
29402940
*
29412941
* Translate infix type `l op r` to `op[l, r]`
29422942
* Translate infix pattern `l op r` to `op(l, r)`
@@ -2953,7 +2953,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29532953
typedUnApply(cpy.Apply(tree)(op, l :: r :: Nil), pt)
29542954
else {
29552955
val app = typedApply(desugar.binop(l, op, r), pt)
2956-
if op.name.isRightAssocOperatorName then
2956+
if op.name.isRightAssocOperatorName && !ctx.mode.is(Mode.QuotedPattern) then
29572957
val defs = new mutable.ListBuffer[Tree]
29582958
def lift(app: Tree): Tree = (app: @unchecked) match
29592959
case Apply(fn, args) =>

Diff for: tests/pos-macros/i19947/Macro_1.scala

+9
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)

Diff for: tests/pos-macros/i19947/Test_2.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Any = expandMacro

0 commit comments

Comments
 (0)