Skip to content

Commit c158ff2

Browse files
authored
fix #32777, regression in type intersection of unions (#32788)
Fortunately, #32771 allows reverting the offending change.
1 parent b7e9493 commit c158ff2

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/subtype.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,14 +2026,8 @@ 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-
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-
}
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);
20372031
e->Runions = oldRunions;
20382032
jl_value_t *i = simple_join(a,b);
20392033
JL_GC_POP();

test/missing.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ end
1616
@test convert(Union{Int, Missing}, 1.0) === 1
1717
@test convert(Union{Nothing, Missing}, missing) === missing
1818
@test convert(Union{Nothing, Missing}, nothing) === nothing
19+
@test convert(Union{Missing, Nothing, Float64}, 1) === 1.0
1920

2021
@test_throws MethodError convert(Missing, 1)
2122
@test_throws MethodError convert(Union{Nothing, Missing}, 1)
@@ -241,6 +242,14 @@ end
241242
@test isa(x, Vector{Union{Int, Missing}})
242243
@test isequal(x, [missing])
243244
@test eltype(adjoint([1, missing])) == Union{Int, Missing}
245+
# issue #32777
246+
let a = [0, nothing, 0.0, missing]
247+
@test a[1] === 0.0
248+
@test a[2] === nothing
249+
@test a[3] === 0.0
250+
@test a[4] === missing
251+
@test a isa Vector{Union{Missing, Nothing, Float64}}
252+
end
244253
end
245254

246255
@testset "== and != on arrays" begin

test/subtype.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,13 @@ end
14151415
@testintersect(Union{Array{T,1},Array{T,2}} where T<:Union{Float32,Float64},
14161416
Union{AbstractMatrix{Float32},AbstractVector{Float32}},
14171417
Union{Array{Float32,2}, Array{Float32,1}})
1418+
let A = Tuple{Type{Union{Missing,T}},Any} where T,
1419+
B = Tuple{Type{Union{Nothing,T}},Any} where T
1420+
I = typeintersect(A, B)
1421+
J = typeintersect(B, A)
1422+
@test I >: Tuple{Type{Union{Nothing,Missing,T}}, Any} where T
1423+
@test J >: Tuple{Type{Union{Nothing,Missing,T}}, Any} where T
1424+
end
14181425

14191426
# issue #29955
14201427
struct M29955{T, TV<:AbstractVector{T}}

0 commit comments

Comments
 (0)