diff --git a/base/reflection.jl b/base/reflection.jl index 8f968ef6065cb..3e8db3dcc3ce8 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -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 @@ -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}}) diff --git a/test/ambiguous.jl b/test/ambiguous.jl index 4c13725763ca6..fa2bc54c269e8 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -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()