Skip to content

Commit a2e7b46

Browse files
committed
restrict shorter printing of wheres to gensym names
1 parent 9472ed9 commit a2e7b46

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

base/show.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ function make_typealias(@nospecialize(x::Type))
583583
end
584584
end
585585

586+
isgensym(s::Symbol) = '#' in string(s)
587+
586588
function show_can_elide(p::TypeVar, wheres::Vector, elide::Int, env::SimpleVector, skip::Int)
587589
elide == 0 && return false
588590
wheres[elide] === p || return false
@@ -612,9 +614,9 @@ function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::
612614
if i == n && egal_var(p, orig[i]) && show_can_elide(p, wheres, elide, env, i)
613615
n -= 1
614616
elide -= 1
615-
elseif p.lb === Union{} && show_can_elide(p, wheres, elide, env, i)
617+
elseif p.lb === Union{} && isgensym(p.name) && show_can_elide(p, wheres, elide, env, i)
616618
elide -= 1
617-
elseif p.ub === Any && show_can_elide(p, wheres, elide, env, i)
619+
elseif p.ub === Any && isgensym(p.name) && show_can_elide(p, wheres, elide, env, i)
618620
elide -= 1
619621
end
620622
end
@@ -624,10 +626,10 @@ function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::
624626
for i = 1:n
625627
p = env[i]
626628
if p isa TypeVar
627-
if p.lb === Union{} && something(findfirst(w -> w === p, wheres), 0) > elide
629+
if p.lb === Union{} && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
628630
print(io, "<:")
629631
show(io, p.ub)
630-
elseif p.ub === Any && something(findfirst(w -> w === p, wheres), 0) > elide
632+
elseif p.ub === Any && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
631633
print(io, ">:")
632634
show(io, p.lb)
633635
else

doc/src/manual/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ consider the two types created by the following declarations:
10341034

10351035
```jldoctest
10361036
julia> const T1 = Array{Array{T, 1} where T, 1}
1037-
Vector{Vector} (alias for Array{Array{<:Any, 1}, 1})
1037+
Vector{Vector} (alias for Array{Array{T, 1} where T, 1})
10381038
10391039
julia> const T2 = Array{Array{T, 1}, 1} where T
10401040
Array{Vector{T}, 1} where T

test/errorshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ let err_str,
432432
@test startswith(sprint(show, which(FunctionLike(), Tuple{})),
433433
"(::$(curmod_prefix)FunctionLike)() in $curmod_str at $sp:$(method_defs_lineno + 7)")
434434
@test startswith(sprint(show, which(StructWithUnionAllMethodDefs{<:Integer}, (Any,))),
435-
"($(curmod_prefix)StructWithUnionAllMethodDefs{<:Integer})(x)")
435+
"($(curmod_prefix)StructWithUnionAllMethodDefs{T} where T<:Integer)(x)")
436436
@test repr("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 1 method)"
437437
@test repr("text/plain", Core.arraysize) == "arraysize (built-in function)"
438438

test/show.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ end
15701570

15711571
let x = TypeVar(:_), y = TypeVar(:_)
15721572
@test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair"
1573-
@test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{<:Any, _1} where _1"
1573+
@test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{_2, _1} where {_1, _2}"
15741574
@test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref}"
15751575
@test repr(UnionAll(y, UnionAll(x, Pair{UnionAll(y,Ref{x}),y}))) == "Pair{Ref{_2}, _1} where {_1, _2}"
15761576
end
@@ -1584,9 +1584,9 @@ let x, y, x
15841584
end
15851585

15861586
let x = TypeVar(:_, Number), y = TypeVar(:_, Number)
1587-
@test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair{<:Number, <:Number}"
1588-
@test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{<:Number, _1} where _1<:Number"
1589-
@test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref{<:Number}, <:Number}"
1587+
@test repr(UnionAll(x, UnionAll(y, Pair{x,y}))) == "Pair{_1, _2} where {_1<:Number, _2<:Number}"
1588+
@test repr(UnionAll(y, UnionAll(x, Pair{x,y}))) == "Pair{_2, _1} where {_1<:Number, _2<:Number}"
1589+
@test repr(UnionAll(x, UnionAll(y, Pair{UnionAll(x,Ref{x}),y}))) == "Pair{Ref{_1} where _1<:Number, _1} where _1<:Number"
15901590
@test repr(UnionAll(y, UnionAll(x, Pair{UnionAll(y,Ref{x}),y}))) == "Pair{Ref{_2}, _1} where {_1<:Number, _2<:Number}"
15911591
end
15921592

@@ -1771,7 +1771,7 @@ end
17711771
@test replstr([[1.0]=>1.0]) == "1-element Vector{Pair{Vector{Float64}, Float64}}:\n [1.0] => 1.0"
17721772

17731773
# issue #28159
1774-
@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)"
1774+
@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)"
17751775

17761776
@test replstr(Vector[Any[1]]) == "1-element Vector{Vector}:\n Any[1]"
17771777
@test replstr(AbstractDict{Integer,Integer}[Dict{Integer,Integer}(1=>2)]) ==
@@ -2166,8 +2166,8 @@ end
21662166
@test string(Union{Nothing, AbstractVecOrMat}) == "Union{Nothing, AbstractVecOrMat}"
21672167
@test string(Union{Nothing, AbstractVecOrMat{<:Integer}}) == "Union{Nothing, AbstractVecOrMat{<:Integer}}"
21682168
@test string(M37012.BStruct{T, T} where T) == "$(curmod_prefix)M37012.B2{T, T} where T"
2169-
@test string(M37012.BStruct{T, S} where {T<:Unsigned, S<:Signed}) == "$(curmod_prefix)M37012.B2{<:Signed, T} where T<:Unsigned"
2170-
@test string(M37012.BStruct{T, S} where {T<:Signed, S<:T}) == "$(curmod_prefix)M37012.B2{<:T, T} where T<:Signed"
2169+
@test string(M37012.BStruct{T, S} where {T<:Unsigned, S<:Signed}) == "$(curmod_prefix)M37012.B2{S, T} where {T<:Unsigned, S<:Signed}"
2170+
@test string(M37012.BStruct{T, S} where {T<:Signed, S<:T}) == "$(curmod_prefix)M37012.B2{S, T} where {T<:Signed, S<:T}"
21712171
@test string(Union{M37012.SimpleU, Nothing}) == "Union{Nothing, $(curmod_prefix)M37012.SimpleU}"
21722172
@test string(Union{M37012.SimpleU, Nothing, T} where T) == "Union{Nothing, $(curmod_prefix)M37012.SimpleU, T} where T"
21732173
@test string(Union{AbstractVector{T}, T} where T) == "Union{AbstractVector{T}, T} where T"

0 commit comments

Comments
 (0)