Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #30346, specificity issue with DynamicPolynomials #30360

Merged
merged 1 commit into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,6 @@ static int obviously_disjoint(jl_value_t *a, jl_value_t *b, int specificity)
for(i=0; i < np; i++) {
jl_value_t *ai = jl_tparam(ad,i);
jl_value_t *bi = jl_tparam(bd,i);
if (!istuple && specificity && jl_has_free_typevars(ai)) {
// X{<:SomeDataType} and X{Union{Y,Z,...}} need to be disjoint to
// avoid this transitivity problem:
// A = Tuple{Type{LinearIndices{N,R}}, LinearIndices{N}} where {N,R}
// B = Tuple{Type{T},T} where T<:AbstractArray
// C = Tuple{Type{Union{Nothing, T}}, Union{Nothing, T}} where T
// A is more specific than B. It would be easy to think B is more specific
// than C, but we can't have that since A should not be more specific than C.
jl_value_t *aub = jl_is_typevar(ai) ? ((jl_tvar_t*)ai)->ub : ai;
jl_value_t *bub = jl_is_typevar(bi) ? ((jl_tvar_t*)bi)->ub : bi;
aub = jl_unwrap_unionall(aub);
bub = jl_unwrap_unionall(bub);
if ((jl_is_typevar(ai) + jl_is_typevar(bi) < 2) &&
aub != (jl_value_t*)jl_any_type && bub != (jl_value_t*)jl_any_type &&
((jl_is_uniontype(aub) && jl_is_datatype(bub) && !in_union(aub, bub) &&
(jl_is_typevar(bi) || !jl_is_typevar(ai))) ||
(jl_is_uniontype(bub) && jl_is_datatype(aub) && !in_union(bub, aub) &&
(jl_is_typevar(ai) || !jl_is_typevar(bi)))))
return 1;
}
if (jl_is_typevar(ai) || jl_is_typevar(bi))
continue;
if (jl_is_type(ai)) {
Expand Down Expand Up @@ -2883,8 +2863,9 @@ static int type_morespecific_(jl_value_t *a, jl_value_t *b, int invariant, jl_ty
if (((jl_tvar_t*)b)->ub == jl_bottom_type)
return 0;
if (jl_has_free_typevars(a)) {
if (type_morespecific_(a, ((jl_tvar_t*)b)->ub, 0, env) ||
eq_msp(a, ((jl_tvar_t*)b)->ub, env))
if (type_morespecific_(a, ((jl_tvar_t*)b)->ub, 0, env))
return 1;
if (eq_msp(a, ((jl_tvar_t*)b)->ub, env))
return num_occurs((jl_tvar_t*)b, env) < 2;
return 0;
}
Expand Down
12 changes: 10 additions & 2 deletions test/specificity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ let N = Tuple{Type{Union{Nothing, T}}, Union{Nothing, T}} where T,
LI = Tuple{Type{LinearIndices{N,R}}, LinearIndices{N}} where {N,R},
A = Tuple{Type{T},T} where T<:AbstractArray
@test args_morespecific(LI, A)
@test !args_morespecific(A, N)
@test !args_morespecific(LI, N)
@test args_morespecific(A, N)
@test args_morespecific(LI, N)
end

# issue #29528
Expand Down Expand Up @@ -298,3 +298,11 @@ end

@test args_morespecific(Tuple{Type{Missing},Any},
Tuple{Type{Union{Nothing, T}},Any} where T)

let A = Tuple{Type{SubString{S}},AbstractString} where S<:AbstractString,
B = Tuple{Type{T},AbstractString} where T<:AbstractString,
C = Tuple{Type{Union{Missing, Nothing, T}},Union{Missing, Nothing, T}} where T
@test args_morespecific(A, B)
@test args_morespecific(B, C)
@test args_morespecific(A, C)
end