diff --git a/base/show.jl b/base/show.jl index 6b6d0e1ebe83aa..01e6afc5f7f4b9 100644 --- a/base/show.jl +++ b/base/show.jl @@ -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) @@ -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) @@ -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) diff --git a/test/show.jl b/test/show.jl index bf820734c809b8..06af7f2a4e1c15 100644 --- a/test/show.jl +++ b/test/show.jl @@ -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]) @@ -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))"