Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTuples made me sad (so I nixed them) #11242

Merged
merged 16 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Vararg method printing
  • Loading branch information
timholy committed May 5, 2016
commit c66aeb332fa5b39470479b98eaa621fab2016005
38 changes: 25 additions & 13 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Method and method table pretty-printing

function argtype_decl(env, n, t) # -> (argname, argtype)
if isvarargtype(t)
return argtype_decl_vararg(env, n, t)
end
if isa(n,Expr)
n = n.args[1] # handle n::T in arg list
end
Expand All @@ -17,20 +14,35 @@ function argtype_decl(env, n, t) # -> (argname, argtype)
if t === Any && !isempty(s)
return s, ""
end
return s, string(t)
if isvarargtype(t)
tt, tn = t.parameters[1], t.parameters[2]
if isa(tn, TypeVar) && !tn.bound
if tt === Any || (isa(tt, TypeVar) && !tt.bound)
return string(s, "..."), ""
else
return s, string_with_env(env, tt) * "..."
end
end
return s, string_with_env(env, "Vararg{", tt, ",", tn, "}")
elseif t == String
return s, "String"
end
return s, string_with_env(env, t)
end

function argtype_decl_vararg(env, n, t)
s = string(n.args[1])
if n.args[2].head == :...
# x... or x::T... declaration
if t.parameters[1] === Any
return string(s, "..."), ""
else
return s, string_with_env(env, t.parameters[1]) * "..."
if isa(n, Expr)
s = string(n.args[1])
if n.args[2].head == :...
# x... or x::T... declaration
if t.parameters[1] === Any
return string(s, "..."), ""
else
return s, string_with_env(env, t.parameters[1]) * "..."
end
elseif t == String
return s, "String"
end
elseif t == String
return s, "String"
end
# x::Vararg, x::Vararg{T}, or x::Vararg{T,N} declaration
s, length(n.args[2].args) < 4 ?
Expand Down
26 changes: 12 additions & 14 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,22 +400,20 @@ function test_mt(f, str)
io = IOBuffer()
show(io, defs)
strio = takebuf_string(io)
strio = split(strio, " at")[1]
@test strio[1:length(str)] == str
end
begin
local f1, f2, f3, f4, f5
f1(x...) = [x...]
f2(x::Vararg{Any}) = [x...]
f3(x::Vararg) = [x...]
f4(x::Vararg{Any,3}) = [x...]
f5{T,N}(A::AbstractArray{T,N}, indexes::Vararg{Int,N}) = [indexes...]
test_mt(f1, "f1(x...)")
test_mt(f2, "f2(x::Vararg{Any})")
test_mt(f3, "f3(x::Vararg{T<:Any})") # FIXME? better as x::Vararg?
# test_mt(f4, "f4(x::Vararg{Any,3})")
intstr = string(Int)
test_mt(f5, "f5{T,N}(A::AbstractArray{T,N}, indexes::Vararg{$intstr,N})")
end
show_f1(x...) = [x...]
show_f2(x::Vararg{Any}) = [x...]
show_f3(x::Vararg) = [x...]
show_f4(x::Vararg{Any,3}) = [x...]
show_f5{T,N}(A::AbstractArray{T,N}, indexes::Vararg{Int,N}) = [indexes...]
test_mt(show_f1, "show_f1(x...)")
test_mt(show_f2, "show_f2(x...)")
test_mt(show_f3, "show_f3(x...)")
test_mt(show_f4, "show_f4(x::Vararg{Any,3})")
intstr = string(Int)
test_mt(show_f5, "show_f5{T,N}(A::AbstractArray{T,N}, indexes::Vararg{$intstr,N})")

# Issue #15525, printing of vcat
@test sprint(show, :([a;])) == ":([a;])"
Expand Down