From 7dc0156732879253bce16fbe19a2a00c0d9c1fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8egh?= Date: Fri, 19 Dec 2014 16:28:30 +0100 Subject: [PATCH] Added so #7714 also takes care of args... when considering a 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. --- base/replutil.jl | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/base/replutil.jl b/base/replutil.jl index e5d96e6e1dd94b..05248950c75d80 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -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