Skip to content

Symbols passed to macros in a module improperly scoped #15085

@jballanc

Description

@jballanc

When a macro is imported from a foreign module, if a symbol is passed as an argument to that macro and used in an escape clause within a quote clause, the symbol has the macro-source-module name prefixed. This does not seem like desirable behavior.

Example:

julia> module X 
           macro p(y) 
             quote 
               println($y) 
             end 
           end 
       end 
X 

julia> using X 

julia> test = "Hello, world" 
"Hello, world" 

julia> @X.p(test) 
ERROR: UndefVarError: test not defined 

julia> macroexpand(:(@X.p(test)))
quote  # none, line 4:
    X.println(X.test)
end

Currently, this can be avoided by a bit of quote-escape-gymnastics:

julia> module X 
           macro q(y) 
             quote 
               println(:($($y))) 
             end 
           end 
       end

julia> @X.q(test) 
Hello, world

julia> macroexpand(:(@X.q(test)))
quote  # none, line 9:
    X.println(test)
end

This is currently causing bugs and other issues for at least a few users as discussed here and here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions