Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parseable repr for undef #33211

Merged
merged 4 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

show(io::IO, ::UndefInitializer) = print(io, "array initializer with undefined values")
function show(io::IO, ::MIME"text/plain", u::UndefInitializer)
print(io, u, ": array initializer with undefined values")
end

# first a few multiline show functions for types defined before the MIME type:

Expand Down
15 changes: 15 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,21 @@ end
Z = Array{Float64}(undef,0,0)
@test eval(Meta.parse(repr(Z))) == Z

@testset "show undef" begin
# issue #33204 - Parseable `repr` for `undef`
@test eval(Meta.parse(repr(undef))) == undef == UndefInitializer()
@test showstr(undef) == "UndefInitializer()"
@test occursin(repr(undef), replstr(undef))
@test occursin("initializer with undefined values", replstr(undef))

vec_undefined = Vector(undef, 2)
vec_initialisers = fill(undef, 2)
@test showstr(vec_undefined) == "Any[#undef, #undef]"
@test showstr(vec_initialisers) == "UndefInitializer[$undef, $undef]"
@test replstr(vec_undefined) == "2-element Array{Any,1}:\n #undef\n #undef"
@test replstr(vec_initialisers) == "2-element Array{UndefInitializer,1}:\n $undef\n $undef"
end

# issue #31065, do not print parentheses for nested dot expressions
@test sprint(Base.show_unquoted, :(foo.x.x)) == "foo.x.x"

Expand Down