From 2c2673b67f1c3b79285412ced8511c4ee19bf5da Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 10 Sep 2019 15:14:21 +0100 Subject: [PATCH 1/4] Restrict verbose `undef` show to MIME"text/plain" --- base/show.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/show.jl b/base/show.jl index cc59d1c29ab7e..82d981709aa5a 100644 --- a/base/show.jl +++ b/base/show.jl @@ -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", ::UndefInitializer) + print(io, "array initializer with undefined values") +end # first a few multiline show functions for types defined before the MIME type: From 14ae0c03d92df7b814d9e54ae0a6aa36404cf899 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 10 Sep 2019 15:37:47 +0100 Subject: [PATCH 2/4] Test `undef` has parseable `repr` --- test/show.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/show.jl b/test/show.jl index 21e1eaa78f134..d161d715d04c5 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1541,6 +1541,13 @@ 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("initializer with undefined values", replstr(undef)) +end + # issue #31065, do not print parentheses for nested dot expressions @test sprint(Base.show_unquoted, :(foo.x.x)) == "foo.x.x" From 80e525aedb895a61c2ae938175cadb31271eb3e4 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 10 Sep 2019 15:47:45 +0100 Subject: [PATCH 3/4] Test `undef` and undefined values show differently --- test/show.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/show.jl b/test/show.jl index d161d715d04c5..40bc2e85c14b9 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1546,6 +1546,13 @@ Z = Array{Float64}(undef,0,0) @test eval(Meta.parse(repr(undef))) == undef == UndefInitializer() @test showstr(undef) == "UndefInitializer()" @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 From 67da9693a4d69b76b630c9c09bf3e6f839846605 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Thu, 12 Sep 2019 15:18:10 +0100 Subject: [PATCH 4/4] Include canonical repr in `undef` text/plain show --- base/show.jl | 4 ++-- test/show.jl | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/base/show.jl b/base/show.jl index 82d981709aa5a..06e8fe52991b0 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -function show(io::IO, ::MIME"text/plain", ::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: diff --git a/test/show.jl b/test/show.jl index 40bc2e85c14b9..0ef9ddf3f071e 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1545,6 +1545,7 @@ Z = Array{Float64}(undef,0,0) # 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)