Skip to content

Commit b2d15f0

Browse files
authored
print @var_str in NamedTuple by show_sym (#42729)
fix #42719
1 parent 1838881 commit b2d15f0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/namedtuple.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ function show(io::IO, t::NamedTuple)
165165
typeinfo = get(io, :typeinfo, Any)
166166
print(io, "(")
167167
for i = 1:n
168-
print(io, fieldname(typeof(t),i), " = ")
168+
show_sym(io, fieldname(typeof(t), i))
169+
print(io, " = ")
169170
show(IOContext(io, :typeinfo =>
170171
t isa typeinfo <: NamedTuple ? fieldtype(typeinfo, i) : Any),
171172
getfield(t, i))

test/show.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,12 @@ end
18431843
# issue #34343
18441844
@test showstr([[1], Int[]]) == "[[1], $Int[]]"
18451845
@test showstr([Dict(1=>1), Dict{Int,Int}()]) == "[Dict(1 => 1), Dict{$Int, $Int}()]"
1846+
1847+
# issue #42719, NamedTuple with @var_str
1848+
@test replstr((; var"a b"=1)) == """(var"a b" = 1,)"""
1849+
@test replstr((; var"#var#"=1)) == """(var"#var#" = 1,)"""
1850+
@test replstr((; var"a"=1, b=2)) == "(a = 1, b = 2)"
1851+
@test replstr((; a=1, b=2)) == "(a = 1, b = 2)"
18461852
end
18471853

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

0 commit comments

Comments
 (0)