diff --git a/src/subtype.c b/src/subtype.c index c01ee54e683be..1213cd53af2f6 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -3176,18 +3176,15 @@ static int merge_env(jl_stenv_t *e, jl_value_t **root, jl_savedenv_t *se, int co } int n = 0; jl_varbinding_t *v = e->vars; - jl_value_t *ub = NULL, *vub = NULL; - JL_GC_PUSH2(&ub, &vub); + jl_value_t *b1 = NULL, *b2 = NULL; + JL_GC_PUSH2(&b1, &b2); while (v != NULL) { - if (v->ub != v->var->ub || v->lb != v->var->lb) { - jl_value_t *lb = jl_svecref(*root, n); - if (v->lb != lb) - jl_svecset(*root, n, lb ? jl_bottom_type : v->lb); - ub = jl_svecref(*root, n+1); - vub = v->ub; - if (vub != ub) - jl_svecset(*root, n+1, ub ? simple_join(ub, vub) : vub); - } + b1 = jl_svecref(*root, n); + b2 = v->lb; + jl_svecset(*root, n, simple_meet(b1, b2)); + b1 = jl_svecref(*root, n+1); + b2 = v->ub; + jl_svecset(*root, n+1, simple_join(b1, b2)); n = n + 3; v = v->prev; } diff --git a/test/subtype.jl b/test/subtype.jl index 70c8c0cb354b6..5bb2037d7852b 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -2020,3 +2020,14 @@ end #issue #43082 struct X43082{A, I, B<:Union{Ref{I},I}}; end @testintersect(Tuple{X43082{T}, Int} where T, Tuple{X43082{Int}, Any}, Tuple{X43082{Int}, Int}) + +#issue #46735 +T46735{B<:Real} = Pair{<:Union{B, Val{<:B}}, <:Union{AbstractMatrix{B}, AbstractMatrix{Vector{B}}}} +@testintersect(T46735{B} where {B}, T46735, !Union{}) +@testintersect(T46735{B} where {B<:Integer}, T46735, !Union{}) +S46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,<:(Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}})} +@testintersect(S46735{B} where {B}, S46735, !Union{}) +@testintersect(S46735{B, M} where {B, M}, S46735, !Union{}) +A46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}}} +@testintersect(A46735{B} where {B}, A46735, !Union{}) +@testintersect(A46735{B, M} where {B, M}, A46735, !Union{})