Skip to content

Fix MethodError printing in case of ambiguity #17008

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

Merged
merged 1 commit into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
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