Skip to content

Argument destructuring returned from macro accidentally assigns global #54701

@Keno

Description

@Keno
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:loweringSyntax lowering (compiler front end, 2nd stage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions