Skip to content

Commit 877e3d7

Browse files
timholyJeffBezanson
authored andcommitted
Fix MethodError printing in case of ambiguity
1 parent 9d2a40b commit 877e3d7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

base/reflection.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ function _methods(f::ANY,t::ANY,lim)
181181
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
182182
return _methods_by_ftype(tt, lim)
183183
end
184-
function methods_including_ambiguous(f::ANY, t::ANY)
185-
ft = isa(f,Type) ? Type{f} : typeof(f)
186-
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
187-
return ccall(:jl_matching_methods, Any, (Any,Cint,Cint), tt, -1, 1)
188-
end
189184
function _methods_by_ftype(t::ANY, lim)
190185
tp = t.parameters::SimpleVector
191186
nu = 1
@@ -255,6 +250,13 @@ end
255250

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

253+
function methods_including_ambiguous(f::ANY, t::ANY)
254+
ft = isa(f,Type) ? Type{f} : typeof(f)
255+
tt = isa(t,Type) ? Tuple{ft, t.parameters...} : Tuple{ft, t...}
256+
ms = ccall(:jl_matching_methods, Any, (Any,Cint,Cint), tt, -1, 1)::Array{Any,1}
257+
return MethodList(Method[m[3] for m in ms], typeof(f).name.mt)
258+
end
259+
258260
function methods(f::ANY)
259261
# return all matches
260262
return methods(f, Tuple{Vararg{Any}})

test/ambiguous.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ end
4343
callambig(x, y) = ambig(x, y)
4444
@test_throws MethodError callambig(0x03, 4)
4545

46+
# Printing ambiguity errors
47+
err = try
48+
ambig(0x03, 4)
49+
catch err
50+
err
51+
end
52+
io = IOBuffer()
53+
Base.showerror(io, err)
54+
lines = split(takebuf_string(io), '\n')
55+
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) at") ||
56+
startswith(str, " ambig(x::Integer, y) at")
57+
@test ambig_checkline(lines[2])
58+
@test ambig_checkline(lines[3])
59+
4660
## Other ways of accessing functions
4761
# Test that non-ambiguous cases work
4862
io = IOBuffer()

0 commit comments

Comments
 (0)