Skip to content

Commit

Permalink
Merge pull request #21965 from JuliaLang/jn/21963
Browse files Browse the repository at this point in the history
Method overwriting by an ambiguity should also invalidate the method cache
  • Loading branch information
vtjnash authored May 29, 2017
2 parents 96e4301 + 8bacb65 commit 67b9b3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,10 +1162,10 @@ static int check_ambiguous_visitor(jl_typemap_entry_t *oldentry, struct typemap_
jl_static_show_func_sig(s, isect);
jl_printf(s, "\nbefore the new definition.\n");
}
return 1; // there may be multiple ambiguities, keep going
}
else if (closure->after) {
if (!msp || closure->after) {
// record that this method definition is being partially replaced
// (either with a real definition, or an ambiguity error)
if (closure->shadowed == NULL) {
closure->shadowed = oldentry->func.value;
}
Expand Down
10 changes: 10 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ cfunction(ambig, Int, (UInt8, Int)) # test for a crash (doesn't throw an error)
ambig(x, y::Integer) = 3
@test_throws MethodError ambig(2, 0x03)

# Method overwriting by an ambiguity should also invalidate the method cache (#21963)
ambig(x::Union{Char, Int8}) = 'r'
@test ambig('c') == 'r'
@test ambig(Int8(1)) == 'r'
@test_throws MethodError ambig(Int16(1))
ambig(x::Union{Char, Int16}) = 's'
@test_throws MethodError ambig('c')
@test ambig(Int8(1)) == 'r'
@test ambig(Int16(1)) == 's'

# Automatic detection of ambiguities
module Ambig1
ambig(x, y) = 1
Expand Down

0 comments on commit 67b9b3e

Please sign in to comment.