Skip to content

Commit

Permalink
Make show_function() use var""-syntax to escape names (JuliaLang#38418)
Browse files Browse the repository at this point in the history
Without this, the result of `show()` is not valid, interpretable julia.
  • Loading branch information
NHDaly committed Nov 13, 2020
1 parent 13aac25 commit 9ecc1f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,10 @@ function show_function(io::IO, f::Function, compact::Bool)
elseif isdefined(mt, :module) && isdefined(mt.module, mt.name) &&
getfield(mt.module, mt.name) === f
if is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main
print(io, mt.name)
show_sym(io, mt.name)
else
print(io, mt.module, ".", mt.name)
print(io, mt.module, ".")
show_sym(io, mt.name)
end
else
show_default(io, f)
Expand Down
4 changes: 4 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ end
# Hidden macro names
@test sprint(show, Expr(:macrocall, Symbol("@#"), nothing, :a)) == ":(@var\"#\" a)"

# PR #38418
module M1 var"#foo#"() = 2 end
@test occursin("M1.var\"#foo#\"", sprint(show, M1.var"#foo#", context = :module=>@__MODULE__))

# issue #12477
@test sprint(show, Union{Int64, Int32, Int16, Int8, Float64}) == "Union{Float64, Int16, Int32, Int64, Int8}"

Expand Down

0 comments on commit 9ecc1f2

Please sign in to comment.