Skip to content

Commit

Permalink
ml-matches: ensure all methods are included (#55365)
Browse files Browse the repository at this point in the history
Some methods were filtered out based simply on visit order, which was
not intentional, with the lim==-1 weak-edges mode.

Fix #55231
  • Loading branch information
vtjnash authored Aug 8, 2024
1 parent 7e1f0be commit 1db5cf7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3669,7 +3669,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
int msp2 = !msp && jl_method_morespecific(m2, m);
if (!msp) {
if (subt || !include_ambiguous || (lim != -1 && msp2)) {
if (subt2 || jl_subtype((jl_value_t*)ti, m2->sig)) {
if (subt2 || ((lim != -1 || (!include_ambiguous && !msp2)) && jl_subtype((jl_value_t*)ti, m2->sig))) {
// this may be filtered out as fully intersected, if applicable later
mayexclude = 1;
}
Expand Down
16 changes: 16 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,20 @@ cc46601(::Type{T}, x::Int) where {T<:AbstractString} = 7
@test length(methods(cc46601, Tuple{Type{<:Integer}, Integer})) == 2
@test length(Base.methods_including_ambiguous(cc46601, Tuple{Type{<:Integer}, Integer})) == 7

# Issue #55231
struct U55231{P} end
struct V55231{P} end
U55231(::V55231) = nothing
(::Type{T})(::V55231) where {T<:U55231} = nothing
@test length(methods(U55231)) == 2
U55231(a, b) = nothing
@test length(methods(U55231)) == 3
struct S55231{P} end
struct T55231{P} end
(::Type{T})(::T55231) where {T<:S55231} = nothing
S55231(::T55231) = nothing
@test length(methods(S55231)) == 2
S55231(a, b) = nothing
@test length(methods(S55231)) == 3

nothing
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7572,7 +7572,7 @@ end
# issue #31696
foo31696(x::Int8, y::Int8) = 1
foo31696(x::T, y::T) where {T <: Int8} = 2
@test length(methods(foo31696)) == 1
@test length(methods(foo31696)) == 2
let T1 = Tuple{Int8}, T2 = Tuple{T} where T<:Int8, a = T1[(1,)], b = T2[(1,)]
b .= a
@test b[1] == (1,)
Expand Down

0 comments on commit 1db5cf7

Please sign in to comment.