Skip to content

Commit 4c28b36

Browse files
authored
fix #31899, type intersection involving Int in upper bound (#31960)
1 parent c9777b0 commit 4c28b36

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/subtype.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,8 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
980980
return var_gt((jl_tvar_t*)y, x, e, param);
981981
if (y == (jl_value_t*)jl_any_type && !jl_has_free_typevars(x))
982982
return 1;
983+
if (x == jl_bottom_type && !jl_has_free_typevars(y))
984+
return 1;
983985
jl_value_t *ux = jl_unwrap_unionall(x);
984986
jl_value_t *uy = jl_unwrap_unionall(y);
985987
if ((x != ux || y != uy) && y != (jl_value_t*)jl_any_type && jl_is_datatype(ux) && jl_is_datatype(uy) &&
@@ -1779,7 +1781,10 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
17791781
jl_tvar_t *newvar = vb->var;
17801782
JL_GC_PUSH2(&res, &newvar);
17811783
// try to reduce var to a single value
1782-
if (obviously_egal(vb->lb, vb->ub)) {
1784+
if (jl_is_long(vb->ub) && jl_is_typevar(vb->lb)) {
1785+
varval = vb->ub;
1786+
}
1787+
else if (obviously_egal(vb->lb, vb->ub)) {
17831788
// given x<:T<:x, substitute x for T
17841789
varval = vb->ub;
17851790
}

test/subtype.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,3 +1509,23 @@ end
15091509

15101510
# issue #26083
15111511
@testintersect(Base.RefValue{<:Tuple}, Ref{Tuple{M}} where M, Base.RefValue{Tuple{M}} where M)
1512+
1513+
# issue #31899
1514+
struct SA{N,L}
1515+
end
1516+
@testintersect(Tuple{Type{SA{Int, L} where L}, Type{SA{Int, Int8}}},
1517+
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
1518+
Union{})
1519+
@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}},
1520+
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {L,N},
1521+
Union{})
1522+
@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}},
1523+
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
1524+
Union{})
1525+
@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L,
1526+
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
1527+
Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L)
1528+
@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L,
1529+
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
1530+
# TODO: this could be narrower
1531+
Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L)

0 commit comments

Comments
 (0)