Skip to content

Commit

Permalink
delete_method: remove method from any pre-existing ambiguities (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 27, 2018
1 parent a2a1506 commit 62ce6d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,15 @@ Make method `m` uncallable and force recompilation of any methods that use(d) it
"""
function delete_method(m::Method)
ccall(:jl_method_table_disable, Cvoid, (Any, Any), get_methodtable(m), m)
if m.ambig !== nothing
for m2 in m.ambig
if m2.ambig !== nothing
i = findfirst(isequal(m), m2.ambig)
i === nothing || deleteat!(m2.ambig, i)
end
end
end
nothing
end

function get_methodtable(m::Method)
Expand Down
12 changes: 12 additions & 0 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,18 @@ Base.delete_method(first(methods(foo)))
@test_throws MethodError foo(1, 1)
@test map(g->g.ambig==nothing, methods(foo)) == [false, false]

# pre-existing ambiguities (#28899)
uambig(::Union{Nothing,Int}) = 1
uambig(::Union{Nothing,Float64}) = 2
@test uambig(1) == 1
@test uambig(1.0) == 2
@test_throws MethodError uambig(nothing)
m = which(uambig, Tuple{Int})
Base.delete_method(m)
@test_throws MethodError uambig(1)
@test uambig(1.0) == 2
@test uambig(nothing) == 2

# multiple deletions and ambiguities
typeparam(::Type{T}, a::Array{T}) where T<:AbstractFloat = 1
typeparam(::Type{T}, a::Array{T}) where T = 2
Expand Down

0 comments on commit 62ce6d0

Please sign in to comment.