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

fix #29955, intersection bugs involving triangular constraints #29986

Merged
merged 1 commit into from
Nov 16, 2018
Merged
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
3 changes: 2 additions & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ static int within_typevar(jl_value_t *t, jl_value_t *vlb, jl_value_t *vub)
else if (!jl_is_type(t)) {
return vlb == jl_bottom_type && vub == (jl_value_t*)jl_any_type;
}
return jl_subtype(vlb, lb) && jl_subtype(ub, vub);
return ((jl_has_free_typevars(vlb) || jl_subtype(vlb, lb)) &&
(jl_has_free_typevars(vub) || jl_subtype(ub, vub)));
}

typedef struct _jl_typestack_t jl_typestack_t;
Expand Down
5 changes: 4 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,10 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
return xlb;
return jl_bottom_type;
}
if (!(subtype_in_env(xlb, yub, e) && subtype_in_env(ylb, xub, e)))
if (R) flip_vars(e);
int ccheck = subtype_in_env(xlb, yub, e) && subtype_in_env(ylb, xub, e);
if (R) flip_vars(e);
if (!ccheck)
return jl_bottom_type;
jl_value_t *ub=NULL, *lb=NULL;
JL_GC_PUSH2(&lb, &ub);
Expand Down
22 changes: 22 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,3 +1357,25 @@ end
@testintersect(Tuple{Vararg{Val{N}, N}} where N,
Tuple{Val{2}, Vararg{Val{3}}},
Union{})

# issue #29955
struct M29955{T, TV<:AbstractVector{T}}
end
@testintersect(M29955,
M29955{<:Any,TV} where TV>:Vector{Float64},
M29955{Float64,TV} where Array{Float64,1}<:TV<:AbstractArray{Float64,1})

struct A29955{T, TV<:AbstractVector{T}, TModel<:M29955{T,TV}}
end
@testintersect(Tuple{Type{A29955{Float64,Array{Float64,1},_1}} where _1,
Any},
Tuple{Type{A29955{T,TV,TM}},
TM} where {T,TV<:AbstractVector{T},TM<:M29955{T,TV}},
Tuple{Type{A29955{Float64,Array{Float64,1},TM}},
TM} where TM<:M29955{Float64,Array{Float64,1}})
let M = M29955{T,Vector{Float64}} where T
@test M == (M29955{T,Vector{Float64}} where T)
@test M{Float64} == M29955{Float64,Vector{Float64}}
@test_throws TypeError M{Float32}
@test_throws TypeError M{Real}
end