Skip to content

Commit c0d4a65

Browse files
authored
fix #34080, regression in printing qualified macro calls (#34081)
1 parent 7090b23 commit c0d4a65

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

base/show.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,14 +1062,16 @@ show_unquoted(io::IO, val::SSAValue, ::Int, ::Int) = print(io, "%", val.id)
10621062
show_unquoted(io::IO, sym::Symbol, ::Int, ::Int) = show_sym(io, sym, allow_macroname=false)
10631063
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.line, ex.file)
10641064
show_unquoted(io::IO, ex::GotoNode, ::Int, ::Int) = print(io, "goto %", ex.label)
1065-
function show_unquoted(io::IO, ex::GlobalRef, ::Int, ::Int)
1065+
show_unquoted(io::IO, ex::GlobalRef, ::Int, ::Int) = show_globalref(io, ex)
1066+
1067+
function show_globalref(io::IO, ex::GlobalRef; allow_macroname=false)
10661068
print(io, ex.mod)
10671069
print(io, '.')
10681070
quoted = !isidentifier(ex.name) && !startswith(string(ex.name), "@")
10691071
parens = quoted && (!isoperator(ex.name) || (ex.name in quoted_syms))
10701072
quoted && print(io, ':')
10711073
parens && print(io, '(')
1072-
show_sym(io, ex.name, allow_macroname=true)
1074+
show_sym(io, ex.name, allow_macroname=allow_macroname)
10731075
parens && print(io, ')')
10741076
nothing
10751077
end
@@ -1175,8 +1177,8 @@ end
11751177
# Wrap symbols for macro names to allow them to be printed literally
11761178
function allow_macroname(ex)
11771179
if (ex isa Symbol && first(string(ex)) == '@') ||
1180+
ex isa GlobalRef ||
11781181
(is_expr(ex, :(.)) && length(ex.args) == 2 &&
1179-
(ex.args[1] isa Symbol || ex.args[1] isa Module) &&
11801182
(is_expr(ex.args[2], :quote) || ex.args[2] isa QuoteNode))
11811183
return Expr(:macroname, ex)
11821184
else
@@ -1483,15 +1485,18 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
14831485
arg1 = args[1]
14841486
if arg1 isa Symbol
14851487
show_sym(io, arg1, allow_macroname=true)
1488+
elseif arg1 isa GlobalRef
1489+
show_globalref(io, arg1, allow_macroname=true)
14861490
elseif is_expr(arg1, :(.)) && length(arg1.args) == 2
1487-
if arg1.args[1] isa Module
1488-
print(io, '(')
1489-
print(io, arg1.args[1])
1490-
print(io, ").")
1491+
m = arg1.args[1]
1492+
if m isa Symbol || m isa GlobalRef || is_expr(m, :(.), 2)
1493+
show_unquoted(io, m)
14911494
else
1492-
print(io, arg1.args[1])
1493-
print(io, '.')
1495+
print(io, "(")
1496+
show_unquoted(io, m)
1497+
print(io, ")")
14941498
end
1499+
print(io, '.')
14951500
if is_expr(arg1.args[2], :quote)
14961501
mname = arg1.args[2].args[1]
14971502
else

test/show.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,13 @@ z856739 = [:a, :b]
10631063
LineNumberNode(0, :none), :a, :b)) ==
10641064
":(#= none:0 =# (Base).@m a b)"
10651065

1066+
# issue #34080
1067+
@test endswith(repr(:(a.b.@c x y)), "a.b.@c x y)")
1068+
@test endswith(repr(:((1+2).@x a)), "(1 + 2).@x a)")
1069+
@test repr(Expr(:(.),
1070+
Expr(:(.), :Base, QuoteNode(Symbol("Enums"))),
1071+
QuoteNode(Symbol("@enum")))) == ":(Base.Enums.var\"@enum\")"
1072+
10661073
# Printing of special macro syntaxes
10671074
# `a b c`
10681075
@test sprint(show, Expr(:macrocall,

0 commit comments

Comments
 (0)