Skip to content

Commit

Permalink
fix #34080, regression in printing qualified macro calls (#34081)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Dec 12, 2019
1 parent 7090b23 commit c0d4a65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
23 changes: 14 additions & 9 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1062,14 +1062,16 @@ show_unquoted(io::IO, val::SSAValue, ::Int, ::Int) = print(io, "%", val.id)
show_unquoted(io::IO, sym::Symbol, ::Int, ::Int) = show_sym(io, sym, allow_macroname=false)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.line, ex.file)
show_unquoted(io::IO, ex::GotoNode, ::Int, ::Int) = print(io, "goto %", ex.label)
function show_unquoted(io::IO, ex::GlobalRef, ::Int, ::Int)
show_unquoted(io::IO, ex::GlobalRef, ::Int, ::Int) = show_globalref(io, ex)

function show_globalref(io::IO, ex::GlobalRef; allow_macroname=false)
print(io, ex.mod)
print(io, '.')
quoted = !isidentifier(ex.name) && !startswith(string(ex.name), "@")
parens = quoted && (!isoperator(ex.name) || (ex.name in quoted_syms))
quoted && print(io, ':')
parens && print(io, '(')
show_sym(io, ex.name, allow_macroname=true)
show_sym(io, ex.name, allow_macroname=allow_macroname)
parens && print(io, ')')
nothing
end
Expand Down Expand Up @@ -1175,8 +1177,8 @@ end
# Wrap symbols for macro names to allow them to be printed literally
function allow_macroname(ex)
if (ex isa Symbol && first(string(ex)) == '@') ||
ex isa GlobalRef ||
(is_expr(ex, :(.)) && length(ex.args) == 2 &&
(ex.args[1] isa Symbol || ex.args[1] isa Module) &&
(is_expr(ex.args[2], :quote) || ex.args[2] isa QuoteNode))
return Expr(:macroname, ex)
else
Expand Down Expand Up @@ -1483,15 +1485,18 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
arg1 = args[1]
if arg1 isa Symbol
show_sym(io, arg1, allow_macroname=true)
elseif arg1 isa GlobalRef
show_globalref(io, arg1, allow_macroname=true)
elseif is_expr(arg1, :(.)) && length(arg1.args) == 2
if arg1.args[1] isa Module
print(io, '(')
print(io, arg1.args[1])
print(io, ").")
m = arg1.args[1]
if m isa Symbol || m isa GlobalRef || is_expr(m, :(.), 2)
show_unquoted(io, m)
else
print(io, arg1.args[1])
print(io, '.')
print(io, "(")
show_unquoted(io, m)
print(io, ")")
end
print(io, '.')
if is_expr(arg1.args[2], :quote)
mname = arg1.args[2].args[1]
else
Expand Down
7 changes: 7 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,13 @@ z856739 = [:a, :b]
LineNumberNode(0, :none), :a, :b)) ==
":(#= none:0 =# (Base).@m a b)"

# issue #34080
@test endswith(repr(:(a.b.@c x y)), "a.b.@c x y)")
@test endswith(repr(:((1+2).@x a)), "(1 + 2).@x a)")
@test repr(Expr(:(.),
Expr(:(.), :Base, QuoteNode(Symbol("Enums"))),
QuoteNode(Symbol("@enum")))) == ":(Base.Enums.var\"@enum\")"

# Printing of special macro syntaxes
# `a b c`
@test sprint(show, Expr(:macrocall,
Expand Down

0 comments on commit c0d4a65

Please sign in to comment.