Skip to content

Commit

Permalink
Added so JuliaLang#7714 also takes care of args... when considering a…
Browse files Browse the repository at this point in the history
… match and

removed the requirement of equal lengths of args. The match also takes
into acount that paremetric methods args needs to have the same type for
one tvar.
  • Loading branch information
dhoegh committed Dec 27, 2014
1 parent 9d0b866 commit 7dc0156
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,51 @@ function showerror(io::IO, e::MethodError)
# Display up to three closest candidates
lines = Array((IOBuffer, Int), 0)
for method in methods(e.f)
n = length(e.args)
if n != length(method.sig)
continue
end
buf = IOBuffer()
print(buf, " $(e.f.env.name)(")
first = true
right_matches = 0
tvars = isa(method.tvars, TypeVar) ?
Dict(method.tvars.name => [T -> method.tvars.lb <: T <: method.tvars.ub, nothing]) :
[tvar.name => [T -> tvar.lb <: T <: tvar.ub, nothing] for tvar in method.tvars]
i = 1
for (arg, sigtype) in Zip2{Any,Any}(e.args, method.sig)
if first
first = false
else
if i != 1
print(buf, ", ")
end
if typeof(arg) <: sigtype
if isa(sigtype, TypeVar)
if (isa(tvars[sigtype.name][2], Void) ?
tvars[sigtype.name][1](typeof(arg)) : tvars[sigtype.name][2] == typeof(arg))
tvars[sigtype.name][2] = typeof(arg)
right_matches += 1
print(buf, "::$(sigtype)")
else
Base.with_output_color(:red, buf) do buf
print(buf, "::$(sigtype)")
end
end
elseif typeof(arg) <: sigtype
right_matches += 1
print(buf, "::$(sigtype)")
elseif (Any...,) == (sigtype,)
right_matches += length(e.args) - i + 1
print(buf, "::$(sigtype)")
else
Base.with_output_color(:red, buf) do buf
print(buf, "::$(sigtype)")
end
end
i += 1
end
if i <= length(method.sig)
for sigtype in method.sig[i:end]
print(buf, ", ")
Base.with_output_color(:red, buf) do buf
print(buf, " ::$(sigtype)")
end
end
end
if right_matches > 0
print(buf, ")")
print(buf, method.func.code.line > 0 ? ") at $(method.func.code.file):$(method.func.code.line)" : ")")
push!(lines, (buf, right_matches))
end
end
Expand Down

0 comments on commit 7dc0156

Please sign in to comment.