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

Argument destructuring returned from macro accidentally assigns global #54701

Closed
Keno opened this issue Jun 6, 2024 · 0 comments · Fixed by #54702
Closed

Argument destructuring returned from macro accidentally assigns global #54701

Keno opened this issue Jun 6, 2024 · 0 comments · Fixed by #54702
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@Keno
Copy link
Member

Keno commented Jun 6, 2024

julia> macro foo()
               quote
                       call(f) = f((1, 2))
                       function $(esc(:foo))()
                               call() do (a, b)
                                       return a+b
                               end
                       end
               end
       end
@foo (macro with 1 method)

julia> @foo
foo (generic function with 1 method)

julia> foo()
3

julia> a
1

julia> b
2

julia> @macroexpand @foo
quote
    #= REPL[1]:3 =#
    var"#7#call"(var"#8#f") = begin
            #= REPL[1]:3 =#
            var"#8#f"((1, 2))
        end
    #= REPL[1]:4 =#
    function foo()
        #= REPL[1]:4 =#
        #= REPL[1]:5 =#
        var"#7#call"() do (Main.a, Main.b)
            #= REPL[1]:6 =#
            return Main.a + Main.b
        end
    end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant