Skip to content

Commit

Permalink
Show closest candidates. Fixes JuliaLang#7686
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Jul 23, 2014
1 parent d91da58 commit 82df15d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ showerror(io::IO, e::ErrorException) = print(io, e.msg)
showerror(io::IO, e::KeyError) = (print(io, "key not found: "); show(io, e.key))
showerror(io::IO, e::InterruptException) = print(io, "interrupt")

RED = "\e[31m"
WHITE = "\e[37m"

function showerror(io::IO, e::MethodError)
name = isgeneric(e.f) ? e.f.env.name : :anonymous
if isa(e.f, DataType)
Expand All @@ -130,6 +133,39 @@ function showerror(io::IO, e::MethodError)
print(io, "you may have intended to import Base.$(name)")
end
end

lines = Array(String, 0)
for method in methods(e.f)
n = length(e.args)
if n != length(method.sig)
continue
end
line = " $(e.f.env.name)("
first = true
all_wrong = true
for i in zip(e.args, method.sig)
if first
first = false
else
line = "$line, "
end
if typeof(i[1]) <: i[2]
all_wrong = false
else
line = "$line$RED"
end
line = "$line::$(i[2])$WHITE"
end
if !all_wrong
push!(lines, "$line)")
end
end
if length(lines) != 0
println(io, "\nClosest candidates are:$WHITE")
for line in lines
println(io, line)
end
end
end

function show_trace_entry(io, fname, file, line, n)
Expand Down

0 comments on commit 82df15d

Please sign in to comment.