Skip to content

Commit 67b9b3e

Browse files
authored
Merge pull request #21965 from JuliaLang/jn/21963
Method overwriting by an ambiguity should also invalidate the method cache
2 parents 96e4301 + 8bacb65 commit 67b9b3e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,10 +1162,10 @@ static int check_ambiguous_visitor(jl_typemap_entry_t *oldentry, struct typemap_
11621162
jl_static_show_func_sig(s, isect);
11631163
jl_printf(s, "\nbefore the new definition.\n");
11641164
}
1165-
return 1; // there may be multiple ambiguities, keep going
11661165
}
1167-
else if (closure->after) {
1166+
if (!msp || closure->after) {
11681167
// record that this method definition is being partially replaced
1168+
// (either with a real definition, or an ambiguity error)
11691169
if (closure->shadowed == NULL) {
11701170
closure->shadowed = oldentry->func.value;
11711171
}

test/ambiguous.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ cfunction(ambig, Int, (UInt8, Int)) # test for a crash (doesn't throw an error)
8585
ambig(x, y::Integer) = 3
8686
@test_throws MethodError ambig(2, 0x03)
8787

88+
# Method overwriting by an ambiguity should also invalidate the method cache (#21963)
89+
ambig(x::Union{Char, Int8}) = 'r'
90+
@test ambig('c') == 'r'
91+
@test ambig(Int8(1)) == 'r'
92+
@test_throws MethodError ambig(Int16(1))
93+
ambig(x::Union{Char, Int16}) = 's'
94+
@test_throws MethodError ambig('c')
95+
@test ambig(Int8(1)) == 'r'
96+
@test ambig(Int16(1)) == 's'
97+
8898
# Automatic detection of ambiguities
8999
module Ambig1
90100
ambig(x, y) = 1

0 commit comments

Comments
 (0)