Skip to content

destructuring in function argument breaks macro expansion #48727

@simeonschaub

Description

@simeonschaub

We unintentionally leak x as a global here:

julia> macro _macroexpand(x, m=__module__)
           :($__source__; macroexpand($m, Expr(:var"hygienic-scope", $(esc(Expr(:quote, x))), $m)))
       end
@_macroexpand (macro with 2 methods)

julia> @_macroexpand f((x,)) = x
:(Main.f((Main.x,)) = begin
          #= REPL[4]:1 =#
          Main.x
      end)

Not only does this have potentially bad side effects, but it also worsens performance due to converting x to a global. Property destructuring has the same issue, but currently errors loudly until #48726 is addressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)macros@macros

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions