diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9539422d94cf..7637bb3d5e2a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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)` @@ -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.QuotedPattern) then val defs = new mutable.ListBuffer[Tree] def lift(app: Tree): Tree = (app: @unchecked) match case Apply(fn, args) => diff --git a/tests/pos-macros/i19947/Macro_1.scala b/tests/pos-macros/i19947/Macro_1.scala new file mode 100644 index 000000000000..dc9ae46eb55f --- /dev/null +++ b/tests/pos-macros/i19947/Macro_1.scala @@ -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) diff --git a/tests/pos-macros/i19947/Test_2.scala b/tests/pos-macros/i19947/Test_2.scala new file mode 100644 index 000000000000..85c0dc845dc4 --- /dev/null +++ b/tests/pos-macros/i19947/Test_2.scala @@ -0,0 +1 @@ +def test: Any = expandMacro