Skip to content

Commit 762801c

Browse files
authored
fix missing methods in ml_matches results (JuliaLang#50962)
This was resulting in it being too aggressive at filtering out "duplicate" results, resulting in possible inference mistakes or missing guardsig entries. Fixes: JuliaLang#50722 (comment)
1 parent 315ff53 commit 762801c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
33703370
continue; // already part of this cycle
33713371
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, childidx);
33723372
jl_method_t *m2 = matc2->method;
3373-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3373+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
33743374
// TODO: we could change this to jl_has_empty_intersection(ti, (jl_value_t*)matc2->spec_types);
33753375
// since we only care about sorting of the intersections the user asked us about
33763376
if (!subt2 && jl_has_empty_intersection(m2->sig, m->sig))
@@ -3515,7 +3515,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
35153515
size_t idx2 = (size_t)stack->items[j];
35163516
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, idx2);
35173517
jl_method_t *m2 = matc2->method;
3518-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3518+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
35193519
// if their intersection contributes to the ambiguity cycle
35203520
// and the contribution of m is fully ambiguous with the portion of the cycle from m2
35213521
if (subt2 || jl_subtype((jl_value_t*)ti, m2->sig)) {

test/ambiguous.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,30 @@ for f in (Ambig8.f, Ambig8.g)
288288
@test f(Int8(0)) == 4
289289
@test_throws MethodError f(0)
290290
@test_throws MethodError f(pi)
291+
let ambig = Ref{Int32}(0)
292+
ms = Base._methods_by_ftype(Tuple{typeof(f), Union{Int,AbstractIrrational}}, nothing, 10, Base.get_world_counter(), false, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
293+
@test ms isa Vector
294+
@test length(ms) == 2
295+
@test ambig[] == 1
296+
end
297+
let ambig = Ref{Int32}(0)
298+
ms = Base._methods_by_ftype(Tuple{typeof(f), Union{Int,AbstractIrrational}}, nothing, -1, Base.get_world_counter(), false, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
299+
@test ms isa Vector
300+
@test length(ms) == 2
301+
@test ambig[] == 1
302+
end
303+
let ambig = Ref{Int32}(0)
304+
ms = Base._methods_by_ftype(Tuple{typeof(f), Union{Int,AbstractIrrational}}, nothing, 10, Base.get_world_counter(), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
305+
@test ms isa Vector
306+
@test length(ms) == 3
307+
@test ambig[] == 1
308+
end
309+
let ambig = Ref{Int32}(0)
310+
ms = Base._methods_by_ftype(Tuple{typeof(f), Union{Int,AbstractIrrational}}, nothing, -1, Base.get_world_counter(), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
311+
@test ms isa Vector
312+
@test length(ms) == 3
313+
@test ambig[] == 1
314+
end
291315
end
292316

293317
module Ambig9

0 commit comments

Comments
 (0)