diff --git a/base/show.jl b/base/show.jl index dc283002bc7515..b45da56baa499b 100644 --- a/base/show.jl +++ b/base/show.jl @@ -583,6 +583,8 @@ function make_typealias(@nospecialize(x::Type)) end end +isgensym(s::Symbol) = '#' in string(s) + function show_can_elide(p::TypeVar, wheres::Vector, elide::Int, env::SimpleVector, skip::Int) elide == 0 && return false wheres[elide] === p || return false @@ -612,9 +614,9 @@ function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres:: if i == n && egal_var(p, orig[i]) && show_can_elide(p, wheres, elide, env, i) n -= 1 elide -= 1 - elseif p.lb === Union{} && show_can_elide(p, wheres, elide, env, i) + elseif p.lb === Union{} && isgensym(p.name) && show_can_elide(p, wheres, elide, env, i) elide -= 1 - elseif p.ub === Any && show_can_elide(p, wheres, elide, env, i) + elseif p.ub === Any && isgensym(p.name) && show_can_elide(p, wheres, elide, env, i) elide -= 1 end end @@ -624,10 +626,10 @@ function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres:: for i = 1:n p = env[i] if p isa TypeVar - if p.lb === Union{} && something(findfirst(w -> w === p, wheres), 0) > elide + if p.lb === Union{} && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide print(io, "<:") show(io, p.ub) - elseif p.ub === Any && something(findfirst(w -> w === p, wheres), 0) > elide + elseif p.ub === Any && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide print(io, ">:") show(io, p.lb) else diff --git a/doc/src/manual/types.md b/doc/src/manual/types.md index 009313545e216d..0be372d4fa6120 100644 --- a/doc/src/manual/types.md +++ b/doc/src/manual/types.md @@ -1034,7 +1034,7 @@ consider the two types created by the following declarations: ```jldoctest julia> const T1 = Array{Array{T, 1} where T, 1} -Vector{Vector} (alias for Array{Array{<:Any, 1}, 1}) +Vector{Vector} (alias for Array{Array{T, 1} where T, 1}) julia> const T2 = Array{Array{T, 1}, 1} where T Array{Vector{T}, 1} where T diff --git a/test/errorshow.jl b/test/errorshow.jl index 83899aa4fff713..736e68dee1ef0e 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -432,7 +432,7 @@ let err_str, @test startswith(sprint(show, which(FunctionLike(), Tuple{})), "(::$(curmod_prefix)FunctionLike)() in $curmod_str at $sp:$(method_defs_lineno + 7)") @test startswith(sprint(show, which(StructWithUnionAllMethodDefs{<:Integer}, (Any,))), - "($(curmod_prefix)StructWithUnionAllMethodDefs{<:Integer})(x)") + "($(curmod_prefix)StructWithUnionAllMethodDefs{T} where T<:Integer)(x)") @test repr("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 1 method)" @test repr("text/plain", Core.arraysize) == "arraysize (built-in function)" diff --git a/test/show.jl b/test/show.jl index d8ed9022f30a4e..734ab84a7e01bd 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1570,7 +1570,7 @@ end let x = TypeVar(:_), y = TypeVar(:_) @test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair" - @test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{<:Any, _1} where _1" + @test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{_2, _1} where {_1, _2}" @test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref}" @test repr(UnionAll(y, UnionAll(x, Pair{UnionAll(y,Ref{x}),y}))) == "Pair{Ref{_2}, _1} where {_1, _2}" end @@ -1584,9 +1584,9 @@ let x, y, x end let x = TypeVar(:_, Number), y = TypeVar(:_, Number) - @test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair{<:Number, <:Number}" - @test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{<:Number, _1} where _1<:Number" - @test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref{<:Number}, <:Number}" + @test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair{_1, _2} where {_1<:Number, _2<:Number}" + @test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{_2, _1} where {_1<:Number, _2<:Number}" + @test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref{_1} where _1<:Number, _1} where _1<:Number" @test repr(UnionAll(y, UnionAll(x, Pair{UnionAll(y,Ref{x}),y}))) == "Pair{Ref{_2}, _1} where {_1<:Number, _2<:Number}" end @@ -1771,7 +1771,7 @@ end @test replstr([[1.0]=>1.0]) == "1-element Vector{Pair{Vector{Float64}, Float64}}:\n [1.0] => 1.0" # issue #28159 - @test replstr([(a=1, b=2), (a=3,c=4)]) == "2-element Vector{NamedTuple{<:Any, Tuple{$Int, $Int}}}:\n (a = 1, b = 2)\n (a = 3, c = 4)" + @test replstr([(a=1, b=2), (a=3,c=4)]) == "2-element Vector{NamedTuple{names, Tuple{$Int, $Int}} where names}:\n (a = 1, b = 2)\n (a = 3, c = 4)" @test replstr(Vector[Any[1]]) == "1-element Vector{Vector}:\n Any[1]" @test replstr(AbstractDict{Integer,Integer}[Dict{Integer,Integer}(1=>2)]) == @@ -2166,8 +2166,8 @@ end @test string(Union{Nothing, AbstractVecOrMat}) == "Union{Nothing, AbstractVecOrMat}" @test string(Union{Nothing, AbstractVecOrMat{<:Integer}}) == "Union{Nothing, AbstractVecOrMat{<:Integer}}" @test string(M37012.BStruct{T, T} where T) == "$(curmod_prefix)M37012.B2{T, T} where T" -@test string(M37012.BStruct{T, S} where {T<:Unsigned, S<:Signed}) == "$(curmod_prefix)M37012.B2{<:Signed, T} where T<:Unsigned" -@test string(M37012.BStruct{T, S} where {T<:Signed, S<:T}) == "$(curmod_prefix)M37012.B2{<:T, T} where T<:Signed" +@test string(M37012.BStruct{T, S} where {T<:Unsigned, S<:Signed}) == "$(curmod_prefix)M37012.B2{S, T} where {T<:Unsigned, S<:Signed}" +@test string(M37012.BStruct{T, S} where {T<:Signed, S<:T}) == "$(curmod_prefix)M37012.B2{S, T} where {T<:Signed, S<:T}" @test string(Union{M37012.SimpleU, Nothing}) == "Union{Nothing, $(curmod_prefix)M37012.SimpleU}" @test string(Union{M37012.SimpleU, Nothing, T} where T) == "Union{Nothing, $(curmod_prefix)M37012.SimpleU, T} where T" @test string(Union{AbstractVector{T}, T} where T) == "Union{AbstractVector{T}, T} where T"