From a3c32862fc5c2757cc34ab1690d3f95bf94a0be1 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 18 Feb 2021 01:59:49 -0500 Subject: [PATCH] ensure to show the whole type, even if the proper subset matched an alias This code should only have been active for make_typealiases, but #38099 already fixed that better, so we can just remove this now. Fixes #39723 (cherry picked from commit b72966751e13f6e4c7571b33d3675d225d29d940) --- base/show.jl | 22 +++++----------------- test/show.jl | 7 ++++++- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/base/show.jl b/base/show.jl index 2fbc8f50ee7374..79ac682f9e22dd 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) && !isvarargtype(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 b0bc4455d990a2..83cee001257022 100644 --- a/test/show.jl +++ b/test/show.jl @@ -2070,12 +2070,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]) @@ -2085,6 +2086,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))"