Skip to content

Commit 36d926f

Browse files
fix missing methods in ml_matches results (JuliaLang#50962) (#227)
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) (cherry picked from commit 762801c) Co-authored-by: Jameson Nash <[email protected]>
1 parent 89c3ab3 commit 36d926f

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
@@ -3518,7 +3518,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
35183518
continue; // already part of this cycle
35193519
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, childidx);
35203520
jl_method_t *m2 = matc2->method;
3521-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3521+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
35223522
// TODO: we could change this to jl_has_empty_intersection(ti, (jl_value_t*)matc2->spec_types);
35233523
// since we only care about sorting of the intersections the user asked us about
35243524
if (!subt2 && jl_has_empty_intersection(m2->sig, m->sig))
@@ -3663,7 +3663,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
36633663
size_t idx2 = (size_t)stack->items[j];
36643664
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, idx2);
36653665
jl_method_t *m2 = matc2->method;
3666-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3666+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
36673667
// if their intersection contributes to the ambiguity cycle
36683668
// and the contribution of m is fully ambiguous with the portion of the cycle from m2
36693669
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)