Skip to content

Commit

Permalink
print @var_str in NamedTuple by show_sym (JuliaLang#42729)
Browse files Browse the repository at this point in the history
  • Loading branch information
inkydragon authored and LilithHafner committed Mar 8, 2022
1 parent 45621af commit ce5cdce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ function show(io::IO, t::NamedTuple)
typeinfo = get(io, :typeinfo, Any)
print(io, "(")
for i = 1:n
print(io, fieldname(typeof(t),i), " = ")
show_sym(io, fieldname(typeof(t), i))
print(io, " = ")
show(IOContext(io, :typeinfo =>
t isa typeinfo <: NamedTuple ? fieldtype(typeinfo, i) : Any),
getfield(t, i))
Expand Down
6 changes: 6 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,12 @@ end
# issue #34343
@test showstr([[1], Int[]]) == "[[1], $Int[]]"
@test showstr([Dict(1=>1), Dict{Int,Int}()]) == "[Dict(1 => 1), Dict{$Int, $Int}()]"

# issue #42719, NamedTuple with @var_str
@test replstr((; var"a b"=1)) == """(var"a b" = 1,)"""
@test replstr((; var"#var#"=1)) == """(var"#var#" = 1,)"""
@test replstr((; var"a"=1, b=2)) == "(a = 1, b = 2)"
@test replstr((; a=1, b=2)) == "(a = 1, b = 2)"
end

@testset "#14684: `display` should print associative types in full" begin
Expand Down

0 comments on commit ce5cdce

Please sign in to comment.