Skip to content

Fix #19369 - duplicate macro execution in unapply methods #19381

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ trait Applications extends Compatibility {
unapplyArgType

val dummyArg = dummyTreeOfType(ownType)
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))(using ctx.addMode(Mode.NoInline))
def unapplyImplicits(unapp: Tree): List[Tree] = {
val res = List.newBuilder[Tree]
def loop(unapp: Tree): Unit = unapp match {
Expand Down
11 changes: 11 additions & 0 deletions tests/pos-macros/i19369/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.quoted._

object Unapplier:
transparent inline def unapply(arg: Any): Option[Int] = ${unapplyImpl('arg)}

def unapplyImpl(using Quotes)(argExpr: Expr[Any]): Expr[Option[Int]] =
import quotes.reflect._
// The code below will recurse, throwing cyclic reference, if it is being inlined too early,
// which is caused by the same problem as the duplicate macro execution here
println(Symbol.spliceOwner.owner.tree)
'{Some(1)}
5 changes: 5 additions & 0 deletions tests/pos-macros/i19369/Main_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {
def main(args: Array[String]): Unit = {
val Unapplier(result) = Some(5)
}
}