Skip to content

Commit

Permalink
fix #32777, regression in type intersection of unions (#32788)
Browse files Browse the repository at this point in the history
Fortunately, #32771 allows reverting the offending change.
(cherry picked from commit c158ff2)
  • Loading branch information
JeffBezanson committed Aug 5, 2019
1 parent a4104fb commit a5d351d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1799,14 +1799,8 @@ 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;
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);
}
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
9 changes: 9 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ end
@test convert(Union{Int, Missing}, 1.0) === 1
@test convert(Union{Nothing, Missing}, missing) === missing
@test convert(Union{Nothing, Missing}, nothing) === nothing
@test convert(Union{Missing, Nothing, Float64}, 1) === 1.0

@test_throws MethodError convert(Missing, 1)
@test_throws MethodError convert(Union{Nothing, Missing}, 1)
Expand Down Expand Up @@ -239,6 +240,14 @@ end
@test isa(x, Vector{Union{Int, Missing}})
@test isequal(x, [missing])
@test eltype(adjoint([1, missing])) == Union{Int, Missing}
# issue #32777
let a = [0, nothing, 0.0, missing]
@test a[1] === 0.0
@test a[2] === nothing
@test a[3] === 0.0
@test a[4] === missing
@test a isa Vector{Union{Missing, Nothing, Float64}}
end
end

@testset "== and != on arrays" begin
Expand Down
7 changes: 7 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,13 @@ 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}})
let A = Tuple{Type{Union{Missing,T}},Any} where T,
B = Tuple{Type{Union{Nothing,T}},Any} where T
I = typeintersect(A, B)
J = typeintersect(B, A)
@test I >: Tuple{Type{Union{Nothing,Missing,T}}, Any} where T
@test J >: Tuple{Type{Union{Nothing,Missing,T}}, Any} where T
end

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

0 comments on commit a5d351d

Please sign in to comment.