Skip to content

Commit

Permalink
Parseable repr for undef (#33211)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrobinson251 authored and JeffBezanson committed Sep 12, 2019
1 parent 47f2800 commit 4887c49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 4887c49

Please sign in to comment.