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

transparent inline unapply method macros are executed twice #19369

Closed
jchyb opened this issue Jan 4, 2024 · 0 comments · Fixed by #19380
Closed

transparent inline unapply method macros are executed twice #19369

jchyb opened this issue Jan 4, 2024 · 0 comments · Fixed by #19380
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@jchyb
Copy link
Contributor

jchyb commented Jan 4, 2024

Compiler version

3.3.1, 3.4.0-RC1-bin-20240103-94e960d-NIGHTLY

Minimized code

Main.scala

@main def main() =
  val Unapplier(result) = Some(5)

Macro.scala

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]] =
    println("a method so nice I'll run it twice")
    '{Some(1)}

Output

compilation output:

a method so nice I'll run it twice
a method so nice I'll run it twice

Expectation

The method should be executed only one time per call, like when using non-transparent inline unapply, or when using transparent inline macros on non-unapply methods.

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 4, 2024
@nicolasstucki nicolasstucki self-assigned this Jan 5, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 5, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 5, 2024
jchyb added a commit to dotty-staging/dotty that referenced this issue Jan 5, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 10, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 11, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 18, 2024
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur pushed a commit that referenced this issue Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
3 participants