From 0d95a1fdab53be3eca0a094eb91b5056d8129a2d Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Sat, 26 Aug 2017 13:19:39 +0200 Subject: [PATCH] fix printing expressions like Ref{<:Real} fixes #23457 Previously they were not explicitly handled by show_unquoted, ending up being printed as Expr. This was not parsable back to their original meaning. --- base/show.jl | 5 +++-- test/show.jl | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/base/show.jl b/base/show.jl index db41a94371ab3..ed2f02245d5eb 100644 --- a/base/show.jl +++ b/base/show.jl @@ -535,6 +535,7 @@ show_unquoted(io::IO, ex, ::Int,::Int) = show(io, ex) const indent_width = 4 const quoted_syms = Set{Symbol}([:(:),:(::),:(:=),:(=),:(==),:(!=),:(===),:(!==),:(=>),:(>=),:(<=)]) +const uni_syms = Set{Symbol}([:(::), :(<:), :(>:)]) const uni_ops = Set{Symbol}([:(+), :(-), :(!), :(¬), :(~), :(<:), :(>:), :(√), :(∛), :(∜)]) const expr_infix_wide = Set{Symbol}([ :(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=), @@ -994,8 +995,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) print(io, head) # type annotation (i.e. "::Int") - elseif head === Symbol("::") && nargs == 1 - print(io, "::") + elseif head in uni_syms && nargs == 1 + print(io, head) show_unquoted(io, args[1], indent) # var-arg declaration or expansion diff --git a/test/show.jl b/test/show.jl index 12786b6ecab3e..a9b8d92d74d4a 100644 --- a/test/show.jl +++ b/test/show.jl @@ -415,6 +415,8 @@ end @test_repr "a::b where T" @test_repr "X where (T=1)" @test_repr "X where T = 1" +@test_repr "Array{<:Real}" +@test_repr "Array{>:Real}" let oldout = STDOUT, olderr = STDERR local rdout, wrout, rderr, wrerr, out, err, rd, wr