@@ -903,7 +903,7 @@ function make_typealiases(@nospecialize(x::Type))
903903 end
904904end
905905
906- function show_unionaliases (io:: IO , x:: Union )
906+ function show_unionaliases (io:: IO , x:: Union , depth :: Integer )
907907 properx = makeproper (io, x)
908908 aliases, applied = make_typealiases (properx)
909909 isempty (aliases) && return false
@@ -985,7 +985,7 @@ function _show_type(io::IO, @nospecialize(x::Type), depth::Int)
985985 show_datatype (io, x, TypeVar[], depth)
986986 return
987987 elseif x isa Union
988- if get (io, :compact , true ):: Bool && show_unionaliases (io, x)
988+ if get (io, :compact , true ):: Bool && show_unionaliases (io, x, depth )
989989 return
990990 end
991991 print (io, " Union" )
@@ -2771,23 +2771,26 @@ function type_depth_limit(str::String, n::Int; maxdepth = nothing)
27712771 return String (take! (output))
27722772end
27732773
2774- function print_type_bicolor (io, @nospecialize (type); color= :normal , inner_color= :light_black , use_color:: Bool = true , depth:: Int )
2775- if depth > max_type_depth (io)
2774+ function print_type_bicolor (io, type; kwargs... )
2775+ depth > max_type_depth (io) && return nothing
2776+ str = sprint (show, type, context= io)
2777+ print_type_bicolor (io, str; kwargs... )
2778+ end
2779+
2780+ function print_type_bicolor (io, str:: String ; color= :normal , inner_color= :light_black , use_color:: Bool = true , depth:: Int = 0 )
2781+ depth > max_type_depth (io) && return nothing
2782+ i = findfirst (' {' , str)
2783+ if ! use_color # fix #41928
2784+ print (io, str)
2785+ elseif i === nothing
2786+ printstyled (io, str; color= color)
27762787 else
2777- str = sprint (show, type, context= io)
2778- i = findfirst (' {' , str)
2779- if ! use_color # fix #41928
2780- print (io, str)
2781- elseif i === nothing
2782- printstyled (io, str; color= color)
2788+ printstyled (io, str[1 : prevind (str,i)]; color= color)
2789+ if endswith (str, " ..." )
2790+ printstyled (io, str[i: prevind (str,end ,3 )]; color= inner_color)
2791+ printstyled (io, " ..." ; color= color)
27832792 else
2784- printstyled (io, str[1 : prevind (str,i)]; color= color)
2785- if endswith (str, " ..." )
2786- printstyled (io, str[i: prevind (str,end ,3 )]; color= inner_color)
2787- printstyled (io, " ..." ; color= color)
2788- else
2789- printstyled (io, str[i: end ]; color= inner_color)
2790- end
2793+ printstyled (io, str[i: end ]; color= inner_color)
27912794 end
27922795 end
27932796end
@@ -2818,7 +2821,7 @@ function ismodulecall(ex::Expr)
28182821 isa (resolvebinding (ex. args[2 ]), Module)
28192822end
28202823
2821- function show (io:: IO , tv:: TypeVar )
2824+ function show (io:: IO , tv:: TypeVar , depth :: Int = 0 )
28222825 # If we are in the `unionall_env`, the type-variable is bound
28232826 # and the type constraints are already printed.
28242827 # We don't need to print it again.
@@ -2828,7 +2831,7 @@ function show(io::IO, tv::TypeVar)
28282831 function show_bound (io:: IO , @nospecialize (b))
28292832 parens = isa (b,UnionAll) && ! print_without_params (b)
28302833 parens && print (io, " (" )
2831- show (io, b)
2834+ show (io, b, depth )
28322835 parens && print (io, " )" )
28332836 end
28342837 lb, ub = tv. lb, tv. ub
@@ -2852,14 +2855,14 @@ function show(io::IO, tv::TypeVar)
28522855 nothing
28532856end
28542857
2855- function show (io:: IO , vm:: Core.TypeofVararg )
2858+ function show (io:: IO , vm:: Core.TypeofVararg , depth :: Int = 0 )
28562859 print (io, " Vararg" )
28572860 if isdefined (vm, :T )
28582861 print (io, " {" )
2859- show (io, vm. T)
2862+ show (io, vm. T, depth + 1 )
28602863 if isdefined (vm, :N )
28612864 print (io, " , " )
2862- show (io, vm. N)
2865+ show (io, vm. N, depth )
28632866 end
28642867 print (io, " }" )
28652868 end
0 commit comments