Skip to content

Commit 24824fe

Browse files
committed
fix #32582, type intersection bug in unions
Caused by 4f8a7b9; reverts part of that.
1 parent ba03920 commit 24824fe

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/subtype.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -2026,8 +2026,14 @@ static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t
20262026
jl_value_t *a=NULL, *b=NULL;
20272027
JL_GC_PUSH2(&a, &b);
20282028
jl_unionstate_t oldRunions = e->Runions;
2029-
a = R ? intersect_all(x, u->a, e) : intersect_all(u->a, x, e);
2030-
b = R ? intersect_all(x, u->b, e) : intersect_all(u->b, x, e);
2029+
if (param == 2) {
2030+
a = R ? intersect(x, u->a, e, param) : intersect(u->a, x, e, param);
2031+
b = R ? intersect(x, u->b, e, param) : intersect(u->b, x, e, param);
2032+
}
2033+
else {
2034+
a = R ? intersect_all(x, u->a, e) : intersect_all(u->a, x, e);
2035+
b = R ? intersect_all(x, u->b, e) : intersect_all(u->b, x, e);
2036+
}
20312037
e->Runions = oldRunions;
20322038
jl_value_t *i = simple_join(a,b);
20332039
JL_GC_POP();

test/subtype.jl

+12
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,18 @@ end
13921392
@testintersect((Tuple{Int, Array{T}} where T),
13931393
(Tuple{Any, Vector{Union{Missing,Nothing,T}}} where T),
13941394
(Tuple{Int, Vector{Union{Missing,Nothing,T}}} where T))
1395+
# issue #32582
1396+
let A = Tuple{Any, Type{Union{Nothing, Int64}}},
1397+
B = Tuple{T, Type{Union{Nothing, T}}} where T,
1398+
I = typeintersect(A, B),
1399+
J = typeintersect(B, A)
1400+
# TODO: improve precision
1401+
@test I >: Tuple{Int64,Type{Union{Nothing, Int64}}}
1402+
@test J >: Tuple{Int64,Type{Union{Nothing, Int64}}}
1403+
end
1404+
@testintersect(Union{Array{T,1},Array{T,2}} where T<:Union{Float32,Float64},
1405+
Union{AbstractMatrix{Float32},AbstractVector{Float32}},
1406+
Union{Array{Float32,2}, Array{Float32,1}})
13951407

13961408
# issue #29955
13971409
struct M29955{T, TV<:AbstractVector{T}}

0 commit comments

Comments
 (0)