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

Subtype: avoid some false alarm in subtype_unionall #47868

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 8 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ static int in_union(jl_value_t *u, jl_value_t *x) JL_NOTSAFEPOINT
return in_union(((jl_uniontype_t*)u)->a, x) || in_union(((jl_uniontype_t*)u)->b, x);
}

static int typevar_in_union(jl_value_t *u) JL_NOTSAFEPOINT
{
if (jl_is_typevar(u)) return 1;
if (!jl_is_uniontype(u)) return 0;
return typevar_in_union(((jl_uniontype_t*)u)->a) || typevar_in_union(((jl_uniontype_t*)u)->b);
}

static int obviously_disjoint(jl_value_t *a, jl_value_t *b, int specificity)
{
if (a == b || a == (jl_value_t*)jl_any_type || b == (jl_value_t*)jl_any_type)
Expand Down Expand Up @@ -1172,7 +1179,7 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
if (jl_is_uniontype(y)) {
if (x == ((jl_uniontype_t*)y)->a || x == ((jl_uniontype_t*)y)->b)
return 1;
if (jl_is_unionall(x))
if (jl_is_unionall(x) && !typevar_in_union(y))
return subtype_unionall(y, (jl_unionall_t*)x, e, 0, param);
int ui = 1;
if (jl_is_typevar(x)) {
Expand Down
16 changes: 13 additions & 3 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,19 @@ T46784{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}}, M, Union{Abstr
@testintersect(T46784{T,S} where {T,S}, T46784, !Union{})
@test_broken T46784 <: T46784{T,S} where {T,S}

# issue 24333
@test Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T
@test Type{Union{Pair,Cvoid}} <: Type{Union{T,Cvoid}} where T
@test only(intersection_env(Val{Union{Val{Val{T}} where {T},Int}}, Val{Union{T,Int}} where T)[2]) === Val{Val{T}} where {T}

# issue 47654
Vec47654{T} = Union{AbstractVector{T}, AbstractVector{Union{T,Nothing}}}
struct Wrapper47654{T, V<:Vec47654{T}}
v::V
end
abstract type P47654{A} end
@test Wrapper47654{P47654, Vector{Union{P47654,Nothing}}} <: Wrapper47654

@testset "known subtype/intersect issue" begin
#issue 45874
# Causes a hang due to jl_critical_error calling back into malloc...
Expand Down Expand Up @@ -2248,9 +2261,6 @@ T46784{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}}, M, Union{Abstr
#issue 26487
@test_broken typeintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T) <: Any

# issue 24333
@test_broken (Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T)

# issue 22123
t1 = Ref{Ref{Ref{Union{Int64, T}}} where T}
t2 = Ref{Ref{Ref{Union{T, S}}} where T} where S
Expand Down