Skip to content

Commit 3b03ade

Browse files
vtjnashKristofferC
authored andcommitted
fix missing methods in ml_matches results (#50962)
This was resulting in it being too aggressive at filtering out "duplicate" results, resulting in possible inference mistakes or missing guardsig entries. Fixes: #50722 (comment) (cherry picked from commit 762801c)
1 parent 5451622 commit 3b03ade

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
@@ -3376,7 +3376,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
33763376
continue; // already part of this cycle
33773377
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, childidx);
33783378
jl_method_t *m2 = matc2->method;
3379-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3379+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
33803380
// TODO: we could change this to jl_has_empty_intersection(ti, (jl_value_t*)matc2->spec_types);
33813381
// since we only care about sorting of the intersections the user asked us about
33823382
if (!subt2 && jl_has_empty_intersection(m2->sig, m->sig))
@@ -3521,7 +3521,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
35213521
size_t idx2 = (size_t)stack->items[j];
35223522
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(t, idx2);
35233523
jl_method_t *m2 = matc2->method;
3524-
int subt2 = matc2->fully_covers != NOT_FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
3524+
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
35253525
// if their intersection contributes to the ambiguity cycle
35263526
// and the contribution of m is fully ambiguous with the portion of the cycle from m2
35273527
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)