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 #31899, type intersection involving Int in upper bound #31960

Merged
merged 1 commit into from
May 8, 2019
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
7 changes: 6 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
return var_gt((jl_tvar_t*)y, x, e, param);
if (y == (jl_value_t*)jl_any_type && !jl_has_free_typevars(x))
return 1;
if (x == jl_bottom_type && !jl_has_free_typevars(y))
return 1;
jl_value_t *ux = jl_unwrap_unionall(x);
jl_value_t *uy = jl_unwrap_unionall(y);
if ((x != ux || y != uy) && y != (jl_value_t*)jl_any_type && jl_is_datatype(ux) && jl_is_datatype(uy) &&
Expand Down Expand Up @@ -1779,7 +1781,10 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
jl_tvar_t *newvar = vb->var;
JL_GC_PUSH2(&res, &newvar);
// try to reduce var to a single value
if (obviously_egal(vb->lb, vb->ub)) {
if (jl_is_long(vb->ub) && jl_is_typevar(vb->lb)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jl_is_typevar(vb->lb)

IIUC, doesn't this also need checks that vb->ub <: jl_any_type && vb->lb >: Union{}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be more precise, I just wanted to be conservative here and also not complicate the code too much.

varval = vb->ub;
}
else if (obviously_egal(vb->lb, vb->ub)) {
// given x<:T<:x, substitute x for T
varval = vb->ub;
}
Expand Down
20 changes: 20 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1509,3 +1509,23 @@ end

# issue #26083
@testintersect(Base.RefValue{<:Tuple}, Ref{Tuple{M}} where M, Base.RefValue{Tuple{M}} where M)

# issue #31899
struct SA{N,L}
end
@testintersect(Tuple{Type{SA{Int, L} where L}, Type{SA{Int, Int8}}},
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
Union{})
@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}},
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {L,N},
Union{})
@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}},
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
Union{})
@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L,
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L)
@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L,
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
# TODO: this could be narrower
Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L)