Skip to content

Commit

Permalink
fix isa fast path for typevars with lower bounds (#32040)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7a75753)
  • Loading branch information
JeffBezanson authored and KristofferC committed May 20, 2019
1 parent a89634b commit 291109b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,10 +1501,18 @@ JL_DLLEXPORT int jl_isa(jl_value_t *x, jl_value_t *t)
if (((jl_datatype_t*)t2)->name == jl_type_typename) {
jl_value_t *tp = jl_tparam0(t2);
if (jl_is_typevar(tp)) {
while (jl_is_typevar(tp))
tp = ((jl_tvar_t*)tp)->ub;
if (!jl_has_free_typevars(tp))
return jl_subtype(x, tp);
if (((jl_tvar_t*)tp)->lb == jl_bottom_type) {
while (jl_is_typevar(tp))
tp = ((jl_tvar_t*)tp)->ub;
if (!jl_has_free_typevars(tp))
return jl_subtype(x, tp);
}
else if (((jl_tvar_t*)tp)->ub == (jl_value_t*)jl_any_type) {
while (jl_is_typevar(tp))
tp = ((jl_tvar_t*)tp)->lb;
if (!jl_has_free_typevars(tp))
return jl_subtype(tp, x);
}
}
}
else {
Expand Down
4 changes: 4 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ function test_Type()
@test !(Tuple{Int,} <: (@UnionAll T<:Tuple Type{T}))
@test isa(Tuple{Int}, (@UnionAll T<:Tuple Type{T}))

@test !isa(Int, Type{>:String})
@test isa(Union{Int,String}, Type{>:String})
@test isa(Any, Type{>:String})

# this matches with T==DataType, since DataType is concrete
@test issub(Tuple{Type{Int},Type{Int8}}, Tuple{T,T} where T)
@test !issub(Tuple{Type{Int},Type{Union{}}}, Tuple{T,T} where T)
Expand Down

0 comments on commit 291109b

Please sign in to comment.