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 #32582, type intersection bug in unions #32590

Merged
merged 1 commit into from
Jul 22, 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
10 changes: 8 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,8 +2026,14 @@ static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t
jl_value_t *a=NULL, *b=NULL;
JL_GC_PUSH2(&a, &b);
jl_unionstate_t oldRunions = e->Runions;
a = R ? intersect_all(x, u->a, e) : intersect_all(u->a, x, e);
b = R ? intersect_all(x, u->b, e) : intersect_all(u->b, x, e);
if (param == 2) {
a = R ? intersect(x, u->a, e, param) : intersect(u->a, x, e, param);
b = R ? intersect(x, u->b, e, param) : intersect(u->b, x, e, param);
}
else {
a = R ? intersect_all(x, u->a, e) : intersect_all(u->a, x, e);
b = R ? intersect_all(x, u->b, e) : intersect_all(u->b, x, e);
}
e->Runions = oldRunions;
jl_value_t *i = simple_join(a,b);
JL_GC_POP();
Expand Down
12 changes: 12 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,18 @@ end
@testintersect((Tuple{Int, Array{T}} where T),
(Tuple{Any, Vector{Union{Missing,Nothing,T}}} where T),
(Tuple{Int, Vector{Union{Missing,Nothing,T}}} where T))
# issue #32582
let A = Tuple{Any, Type{Union{Nothing, Int64}}},
B = Tuple{T, Type{Union{Nothing, T}}} where T,
I = typeintersect(A, B),
J = typeintersect(B, A)
# TODO: improve precision
@test I >: Tuple{Int64,Type{Union{Nothing, Int64}}}
@test J >: Tuple{Int64,Type{Union{Nothing, Int64}}}
end
@testintersect(Union{Array{T,1},Array{T,2}} where T<:Union{Float32,Float64},
Union{AbstractMatrix{Float32},AbstractVector{Float32}},
Union{Array{Float32,2}, Array{Float32,1}})

# issue #29955
struct M29955{T, TV<:AbstractVector{T}}
Expand Down