Skip to content

Commit

Permalink
Method overwriting by an ambiguity should also invalidate the method …
Browse files Browse the repository at this point in the history
…cache

fix #21963

Ref #21965
(cherry picked from commit 8bacb65)
  • Loading branch information
vtjnash committed Sep 14, 2017
1 parent 02276e0 commit ef700d7
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 ef700d7

Please sign in to comment.