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

Macro Inconsistency using Module Qualification #32301

Open
twavv opened this issue Jun 12, 2019 · 0 comments
Open

Macro Inconsistency using Module Qualification #32301

twavv opened this issue Jun 12, 2019 · 0 comments
Labels
parser Language parsing and surface syntax

Comments

@twavv
Copy link
Contributor

twavv commented Jun 12, 2019

For context, this is for JuliaGizmos/WebIO.jl#306.

Simplified, we want to have a macro that accepts a do-block argument.

macro foo(f, ex...)
    @show f
	return :(nothing)
end

This works just fine.

julia> @foo(a, b, c) do x, y, z
           println("Hello!")
       end
f = :((x, y, z)->begin
          #= REPL[2]:2 =#
          println("Hello!")
      end)

However, things get more interesting when we have to qualify the name of @foo because it's in a module.

julia> module FooModule
       macro foo(f, ex...)
           @show f
           return :(nothing)
       end
       end

Putting the @ on the macro name doesn't work.

julia> FooModule.@foo(a, b, c) do x, y z
           println("Hello!")
       end
ERROR: syntax: invalid syntax "FooModule.@foo # REPL[2], line 1 a b c do x, y
    # REPL[2], line 1
    z
    # REPL[2], line 2
    println("Hello!")
end"

while putting the @ in front of the module name does.

julia> @FooModule.foo(a, b, c) do x, y, z
           println("Hello!")
       end
f = :((x, y, z)->begin
          #= REPL[6]:2 =#
          println("Hello!")
      end)

The macro expansion returns strangeness (it should return Main.FooModule.nothing since that's... what the macro expands to).

julia> @macroexpand FooModule.@foo(a, b, c) do x, y z
           println("Hello!")
       end
:($(Expr(:., :FooModule, :($(Expr(:copyast, :($(QuoteNode(:(#= REPL[3]:1 =# @foo a b c do x, y
      #= REPL[3]:1 =#
      z
      #= REPL[3]:2 =#
      println("Hello!")
  end))))))))))

It's worth nothing that the macro expansion of @FooModule.foo doesn't even work.

This is adjacent to #1769.

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

2 participants