Skip to content

Commit

Permalink
Fix MethodError printing in case of ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored and JeffBezanson committed Jun 21, 2016
1 parent 9d2a40b commit 111d72a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 7 additions & 5 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ function _methods(f::ANY,t::ANY,lim)
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
return _methods_by_ftype(tt, lim)
end
function methods_including_ambiguous(f::ANY, t::ANY)
ft = isa(f,Type) ? Type{f} : typeof(f)
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
return ccall(:jl_matching_methods, Any, (Any,Cint,Cint), tt, -1, 1)
end
function _methods_by_ftype(t::ANY, lim)
tp = t.parameters::SimpleVector
nu = 1
Expand Down Expand Up @@ -255,6 +250,13 @@ end

methods(f::Builtin) = MethodList(Method[], typeof(f).name.mt)

function methods_including_ambiguous(f::ANY, t::ANY)
ft = isa(f,Type) ? Type{f} : typeof(f)
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
ms = ccall(:jl_matching_methods, Any, (Any,Cint,Cint), tt, -1, 1)::Array{Any,1}
return MethodList(Method[m[3] for m in ms], typeof(f).name.mt)
end

function methods(f::ANY)
# return all matches
return methods(f, Tuple{Vararg{Any}})
Expand Down
15 changes: 15 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ end
callambig(x, y) = ambig(x, y)
@test_throws MethodError callambig(0x03, 4)

# Printing ambiguity errors
let err = try
ambig(0x03, 4)
catch _e_
_e_
end
io = IOBuffer()
Base.showerror(io, err)
lines = split(takebuf_string(io), '\n')
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) at") ||
startswith(str, " ambig(x::Integer, y) at")
@test ambig_checkline(lines[2])
@test ambig_checkline(lines[3])
end

## Other ways of accessing functions
# Test that non-ambiguous cases work
io = IOBuffer()
Expand Down

0 comments on commit 111d72a

Please sign in to comment.