Skip to content

Commit

Permalink
Handle Vararg in signature in methodshow
Browse files Browse the repository at this point in the history
The parameters of `sig` are not guaranteed to match the arguments
that were passed on method construction, since the type may have
been normalized. This will become more pronounced after JuliaLang#31681,
but with OpaqueClosure we now have some method whose sig is
Tuple{Vararg{Any}}, so we might as well make this change now.
Of course, we may want to print OpaqueClosure methods differently
in general, but that's a question for another time, once we've
worked out exactly what the sig fields of OpaqueClosure methods
should look like.
  • Loading branch information
Keno authored and antoine-levitt committed May 9, 2021
1 parent 66e19c4 commit 138f824
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ function strip_gensym(sym)
end

function argtype_decl(env, n, @nospecialize(sig::DataType), i::Int, nargs, isva::Bool) # -> (argname, argtype)
t = sig.parameters[i]
if i == nargs && isva && !isvarargtype(t)
t = Vararg{t,length(sig.parameters)-nargs+1}
t = sig.parameters[unwrapva(min(i, end))]
if i == nargs && isva
va = sig.parameters[end]
if isvarargtype(va) && (!isdefined(va, :N) || !isa(va.N, Int))
t = va
else
ntotal = length(sig.parameters)
isvarargtype(va) && (ntotal += va.N - 1)
t = Vararg{t,ntotal-nargs+1}
end
end
if isa(n,Expr)
n = n.args[1] # handle n::T in arg list
Expand Down Expand Up @@ -62,7 +69,7 @@ function arg_decl_parts(m::Method, html=false)
end
decls = Tuple{String,String}[argtype_decl(show_env, argnames[i], sig, i, m.nargs, m.isva)
for i = 1:m.nargs]
decls[1] = ("", sprint(show_signature_function, sig.parameters[1], false, decls[1][1], html,
decls[1] = ("", sprint(show_signature_function, unwrapva(sig.parameters[1]), false, decls[1][1], html,
context = show_env))
else
decls = Tuple{String,String}[("", "") for i = 1:length(sig.parameters::SimpleVector)]
Expand Down

0 comments on commit 138f824

Please sign in to comment.