Skip to content

Commit

Permalink
fix JuliaLang#39521, obvious_subtype issue with Type{} and diagonal (
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 5, 2021
1 parent 7d34b0d commit 6159633
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1739,17 +1739,19 @@ static int obvious_subtype(jl_value_t *x, jl_value_t *y, jl_value_t *y0, int *su
*subtype = 0;
return 1;
}
if (jl_is_type_type(a1) && jl_is_type(jl_tparam0(a1))) {
a1 = jl_typeof(jl_tparam0(a1));
jl_value_t *a1u = jl_unwrap_unionall(a1);
if (jl_is_type_type(a1u) && jl_is_type(jl_tparam0(a1u))) {
a1 = jl_typeof(jl_tparam0(a1u));
}
for (; i < nparams_expanded_x; i++) {
jl_value_t *a = (vx != JL_VARARG_NONE && i >= npx - 1) ? vxt : jl_tparam(x, i);
if (i > npy && jl_is_typevar(b)) { // i == npy implies a == a1
// diagonal rule: all the later parameters are also constrained to be type-equal to the first
jl_value_t *a2 = a;
if (jl_is_type_type(a) && jl_is_type(jl_tparam0(a))) {
jl_value_t *au = jl_unwrap_unionall(a);
if (jl_is_type_type(au) && jl_is_type(jl_tparam0(au))) {
// if a is exactly Type{T}, then use the concrete typeof(T) instead here
a2 = jl_typeof(jl_tparam0(a));
a2 = jl_typeof(jl_tparam0(au));
}
if (!obviously_egal(a1, a2)) {
if (obvious_subtype(a2, a1, y0, subtype)) {
Expand Down
4 changes: 4 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1868,3 +1868,7 @@ f39218(::T, ::T) where {T<:AB39218} = false
g39218(a, b) = (@nospecialize; if a isa AB39218 && b isa AB39218; f39218(a, b); end;)
@test g39218(A39218(), A39218()) === false
@test_throws MethodError g39218(A39218(), B39218())

# issue #39521
@test Tuple{Type{Tuple{A}} where A, DataType, DataType} <: Tuple{Vararg{B}} where B
@test Tuple{DataType, Type{Tuple{A}} where A, DataType} <: Tuple{Vararg{B}} where B

0 comments on commit 6159633

Please sign in to comment.