Skip to content

Commit

Permalink
ensure to show the whole type, even if the proper subset matched an a…
Browse files Browse the repository at this point in the history
…lias

This code should only have been active for make_typealiases, but JuliaLang#38099
already fixed that better, so we can just remove this now.

Fixes JuliaLang#39723
  • Loading branch information
vtjnash authored and ElOceanografo committed May 4, 2021
1 parent da07bef commit dfddd66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
22 changes: 5 additions & 17 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,26 +522,12 @@ function makeproper(io::IO, x::Type)
end
end
end
if x isa Union
y = []
normal = true
for typ in uniontypes(x)
if isa(typ, TypeVar)
normal = false
else
push!(y, typ)
end
end
if !normal
properx = rewrap_unionall(Union{y...}, properx)
end
end
has_free_typevars(properx) && return Any
return properx
end

function make_typealias(@nospecialize(x::Type))
Any <: x && return
Any === x && return
x <: Tuple && return
mods = modulesof!(Set{Module}(), x)
Core in mods && push!(mods, Base)
Expand Down Expand Up @@ -681,7 +667,7 @@ function show_typealias(io::IO, x::Type)
end

function make_typealiases(@nospecialize(x::Type))
Any <: x && return Core.svec(), Union{}
Any === x && return Core.svec(), Union{}
x <: Tuple && return Core.svec(), Union{}
mods = modulesof!(Set{Module}(), x)
Core in mods && push!(mods, Base)
Expand All @@ -701,7 +687,9 @@ function make_typealiases(@nospecialize(x::Type))
if alias isa Type && !has_free_typevars(alias) && !print_without_params(alias) && !(alias <: Tuple)
(ti, env) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), x, alias)::SimpleVector
ti === Union{} && continue
mod in modulesof!(Set{Module}(), alias) || continue # make sure this alias wasn't from an unrelated part of the Union
# make sure this alias wasn't from an unrelated part of the Union
mod2 = modulesof!(Set{Module}(), alias)
mod in mod2 || (mod === Base && Core in mods) || continue
env = env::SimpleVector
applied = alias
if !isempty(env)
Expand Down
7 changes: 6 additions & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2071,12 +2071,13 @@ end
end

module M37012
export AValue, B2
export AValue, B2, SimpleU
struct AnInteger{S<:Integer} end
struct AStruct{N} end
const AValue{S} = Union{AStruct{S}, AnInteger{S}}
struct BStruct{T,S} end
const B2{S,T} = BStruct{T,S}
const SimpleU = Union{AnInteger, AStruct, BStruct}
end
@test Base.make_typealias(M37012.AStruct{1}) === nothing
@test isempty(Base.make_typealiases(M37012.AStruct{1})[1])
Expand All @@ -2086,6 +2087,10 @@ end
@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{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, T, $(curmod_prefix)M37012.SimpleU} where T"
@test string(Union{AbstractVector{T}, T} where T) == "Union{AbstractVector{T}, T} where T"
@test string(Union{AbstractVector, T} where T) == "Union{T, AbstractVector{T} where T} where T"

@test sprint(show, :(./)) == ":((./))"
@test sprint(show, :((.|).(.&, b))) == ":((.|).((.&), b))"
Expand Down

0 comments on commit dfddd66

Please sign in to comment.