Skip to content

Commit 38582b2

Browse files
JeffBezansonararslan
authored andcommitted
fix printing of UnionAll in static_show (#23832)
(cherry picked from commit 107a83b)
1 parent fed1e23 commit 38582b2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/rtutils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
537537
else if (vt == jl_simplevector_type) {
538538
n += jl_show_svec(out, (jl_svec_t*)v, "svec", "(", ")");
539539
}
540+
else if (v == (jl_value_t*)jl_unionall_type) {
541+
// avoid printing `typeof(Type)` for `UnionAll`.
542+
n += jl_printf(out, "UnionAll");
543+
}
540544
else if (vt == jl_datatype_type) {
541545
jl_datatype_t *dv = (jl_datatype_t*)v;
542546
jl_sym_t *globname = dv->name->mt != NULL ? dv->name->mt->name : NULL;

test/show.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,45 @@ end
672672

673673
@test sprint(show, Main) == "Main"
674674

675+
# static_show
676+
677+
function static_shown(x)
678+
p = Pipe()
679+
Base.link_pipe(p; julia_only_read=true, julia_only_write=true)
680+
ccall(:jl_static_show, Void, (Ptr{Void}, Any), p.in, x)
681+
@async close(p.in)
682+
return read(p.out, String)
683+
end
684+
685+
# Test for PR 17803
686+
@test static_shown(Int128(-1)) == "Int128(0xffffffffffffffffffffffffffffffff)"
687+
688+
# PR #22160
689+
@test static_shown(:aa) == ":aa"
690+
@test static_shown(:+) == ":+"
691+
@test static_shown(://) == "://"
692+
@test static_shown(://=) == "://="
693+
@test static_shown(Symbol("")) == "Symbol(\"\")"
694+
@test static_shown(Symbol("a/b")) == "Symbol(\"a/b\")"
695+
@test static_shown(Symbol("a-b")) == "Symbol(\"a-b\")"
696+
@test static_shown(UnionAll) == "UnionAll"
697+
698+
@test static_shown(QuoteNode(:x)) == ":(:x)"
699+
700+
# Test @show
701+
let fname = tempname()
702+
try
703+
open(fname, "w") do fout
704+
redirect_stdout(fout) do
705+
@show zeros(2, 2)
706+
end
707+
end
708+
@test read(fname, String) == "zeros(2, 2) = 2×2 Array{Float64,2}:\n 0.0 0.0\n 0.0 0.0\n"
709+
finally
710+
rm(fname, force=true)
711+
end
712+
end
713+
675714
struct f_with_params{t} <: Function
676715
end
677716

0 commit comments

Comments
 (0)