Skip to content

Commit c06ae8b

Browse files
Refactor show_typeparams
1 parent b4c12f4 commit c06ae8b

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

base/show.jl

+24-19
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ function show_can_elide(p::TypeVar, wheres::Vector, elide::Int, env::SimpleVecto
695695
return true
696696
end
697697

698-
function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::Vector)
698+
show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::Vector) =
699+
show(io, string_typeparams(io, env, orig, wheres))
700+
701+
function string_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::Vector)
699702
n = length(env)
700703
elide = length(wheres)
701704
function egal_var(p::TypeVar, @nospecialize o)
@@ -716,29 +719,31 @@ function show_typeparams(io::IO, env::SimpleVector, orig::SimpleVector, wheres::
716719
end
717720
end
718721
end
719-
if n > 0
720-
print(io, "{")
721-
for i = 1:n
722-
p = env[i]
723-
if p isa TypeVar
724-
if p.lb === Union{} && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
725-
print(io, "<:")
726-
show(io, p.ub)
727-
elseif p.ub === Any && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
728-
print(io, ">:")
729-
show(io, p.lb)
722+
723+
s_result = if n > 0
724+
params_string = join(
725+
map(1:n) do i
726+
p = env[i]
727+
suffix = i < n ? ", " : ""
728+
if p isa TypeVar
729+
if p.lb === Union{} && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
730+
string("<:", p.ub, suffix)
731+
elseif p.ub === Any && something(findfirst(@nospecialize(w) -> w === p, wheres), 0) > elide
732+
string(">:", p.lb, suffix)
733+
else
734+
string(p, suffix)
735+
end
730736
else
731-
show(io, p)
737+
string(p, suffix)
732738
end
733-
else
734-
show(io, p)
735739
end
736-
i < n && print(io, ", ")
737-
end
738-
print(io, "}")
740+
)
741+
string("{", params_string, "}")
742+
else
743+
""
739744
end
740745
resize!(wheres, elide)
741-
nothing
746+
return s_result
742747
end
743748

744749
function show_typealias(io::IO, name::GlobalRef, x::Type, env::SimpleVector, wheres::Vector)

0 commit comments

Comments
 (0)