Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid spurious val binding in quote pattern #19948

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3003,8 +3003,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 @@ -3021,7 +3021,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