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

Printing of macro symbols displays like a macrocall #32354

Closed
mbauman opened this issue Jun 18, 2019 · 4 comments · Fixed by #32408
Closed

Printing of macro symbols displays like a macrocall #32354

mbauman opened this issue Jun 18, 2019 · 4 comments · Fixed by #32408
Labels
display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia

Comments

@mbauman
Copy link
Sponsor Member

mbauman commented Jun 18, 2019

MWE:

julia> @macroexpand @which @which
:(InteractiveUtils.which(@which, Tuple{LineNumberNode,Module}))

julia> dump(@macroexpand @which @which)
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: GlobalRef
      mod: Module InteractiveUtils
      name: Symbol which
    2: Symbol @which
    3: Tuple{LineNumberNode,Module} <: Any

This should protect the macro name and print it as a Symbol("@which").

@mbauman mbauman added good first issue Indicates a good issue for first-time contributors to Julia display and printing Aesthetics and correctness of printed representations of objects. labels Jun 18, 2019
@JeffBezanson
Copy link
Sponsor Member

Looks like a more general problem:

julia> Symbol("##")
Symbol("##")

julia> Expr(:tuple, Symbol("##"))
:((##,))

So there's some code for this, but it's not used inside expressions.

@c42f
Copy link
Member

c42f commented Jun 24, 2019

More entertainment:

julia> Expr(:tuple, Symbol("a-b"))
:((a-b,))

c42f added a commit that referenced this issue Jun 24, 2019
WIP: Still broken for `Expr(:macrocall, mname)`

Fix #32354
c42f added a commit that referenced this issue Jun 25, 2019
@c42f
Copy link
Member

c42f commented Jun 26, 2019

So I've got a fix for this over at #23408, but It's worth noting that it dramatically uglifies printing of symbols generated by macro hygiene, even as it makes the resulting Exprs valid.

julia> macro ugly()
           quote
               x = 1
               y = 2
           end
       end
@ugly (macro with 1 method)

julia> @macroexpand @ugly
quote
    #= REPL[30]:3 =#
    $(Symbol("#57#x")) = 1
    #= REPL[30]:4 =#
    $(Symbol("#58#y")) = 2
end

Of course, for non-trivial macros it's a lot worse.

@c42f
Copy link
Member

c42f commented Jun 26, 2019

On the up side, the result of printing such expanded forms is actually valid code with those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants