Skip to content

Commit e4aa541

Browse files
authored
fix #30346, specificity issue with DynamicPolynomials (#30360)
1 parent 897df72 commit e4aa541

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

src/subtype.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -322,26 +322,6 @@ static int obviously_disjoint(jl_value_t *a, jl_value_t *b, int specificity)
322322
for(i=0; i < np; i++) {
323323
jl_value_t *ai = jl_tparam(ad,i);
324324
jl_value_t *bi = jl_tparam(bd,i);
325-
if (!istuple && specificity && jl_has_free_typevars(ai)) {
326-
// X{<:SomeDataType} and X{Union{Y,Z,...}} need to be disjoint to
327-
// avoid this transitivity problem:
328-
// A = Tuple{Type{LinearIndices{N,R}}, LinearIndices{N}} where {N,R}
329-
// B = Tuple{Type{T},T} where T<:AbstractArray
330-
// C = Tuple{Type{Union{Nothing, T}}, Union{Nothing, T}} where T
331-
// A is more specific than B. It would be easy to think B is more specific
332-
// than C, but we can't have that since A should not be more specific than C.
333-
jl_value_t *aub = jl_is_typevar(ai) ? ((jl_tvar_t*)ai)->ub : ai;
334-
jl_value_t *bub = jl_is_typevar(bi) ? ((jl_tvar_t*)bi)->ub : bi;
335-
aub = jl_unwrap_unionall(aub);
336-
bub = jl_unwrap_unionall(bub);
337-
if ((jl_is_typevar(ai) + jl_is_typevar(bi) < 2) &&
338-
aub != (jl_value_t*)jl_any_type && bub != (jl_value_t*)jl_any_type &&
339-
((jl_is_uniontype(aub) && jl_is_datatype(bub) && !in_union(aub, bub) &&
340-
(jl_is_typevar(bi) || !jl_is_typevar(ai))) ||
341-
(jl_is_uniontype(bub) && jl_is_datatype(aub) && !in_union(bub, aub) &&
342-
(jl_is_typevar(ai) || !jl_is_typevar(bi)))))
343-
return 1;
344-
}
345325
if (jl_is_typevar(ai) || jl_is_typevar(bi))
346326
continue;
347327
if (jl_is_type(ai)) {
@@ -2883,8 +2863,9 @@ static int type_morespecific_(jl_value_t *a, jl_value_t *b, int invariant, jl_ty
28832863
if (((jl_tvar_t*)b)->ub == jl_bottom_type)
28842864
return 0;
28852865
if (jl_has_free_typevars(a)) {
2886-
if (type_morespecific_(a, ((jl_tvar_t*)b)->ub, 0, env) ||
2887-
eq_msp(a, ((jl_tvar_t*)b)->ub, env))
2866+
if (type_morespecific_(a, ((jl_tvar_t*)b)->ub, 0, env))
2867+
return 1;
2868+
if (eq_msp(a, ((jl_tvar_t*)b)->ub, env))
28882869
return num_occurs((jl_tvar_t*)b, env) < 2;
28892870
return 0;
28902871
}

test/specificity.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ let N = Tuple{Type{Union{Nothing, T}}, Union{Nothing, T}} where T,
230230
LI = Tuple{Type{LinearIndices{N,R}}, LinearIndices{N}} where {N,R},
231231
A = Tuple{Type{T},T} where T<:AbstractArray
232232
@test args_morespecific(LI, A)
233-
@test !args_morespecific(A, N)
234-
@test !args_morespecific(LI, N)
233+
@test args_morespecific(A, N)
234+
@test args_morespecific(LI, N)
235235
end
236236

237237
# issue #29528
@@ -298,3 +298,11 @@ end
298298

299299
@test args_morespecific(Tuple{Type{Missing},Any},
300300
Tuple{Type{Union{Nothing, T}},Any} where T)
301+
302+
let A = Tuple{Type{SubString{S}},AbstractString} where S<:AbstractString,
303+
B = Tuple{Type{T},AbstractString} where T<:AbstractString,
304+
C = Tuple{Type{Union{Missing, Nothing, T}},Union{Missing, Nothing, T}} where T
305+
@test args_morespecific(A, B)
306+
@test args_morespecific(B, C)
307+
@test args_morespecific(A, C)
308+
end

0 commit comments

Comments
 (0)