diff --git a/src/subtype.c b/src/subtype.c index 8eb6313954263..b4410ee911d6b 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -520,11 +520,9 @@ static int is_leaf_bound(jl_value_t *v) return !jl_is_type(v) && !jl_is_typevar(v); } -static int is_leaf_typevar(jl_value_t *v) +static int is_leaf_typevar(jl_tvar_t *v) { - if (jl_is_typevar(v)) - return is_leaf_typevar(((jl_tvar_t*)v)->lb); - return is_leaf_bound(v); + return is_leaf_bound(v->lb); } static jl_value_t *widen_Type(jl_value_t *t) @@ -630,7 +628,7 @@ static int subtype_unionall(jl_value_t *t, jl_unionall_t *u, jl_stenv_t *e, int8 // !( Tuple{Int, String} <: Tuple{T, T} where T) // Then check concreteness by checking that the lower bound is not an abstract type. int diagonal = !vb.occurs_inv && vb.occurs_cov > 1; - if (ans && (vb.concrete || (diagonal && is_leaf_typevar((jl_value_t*)u->var)))) { + if (ans && (vb.concrete || (diagonal && is_leaf_typevar(u->var)))) { if (vb.concrete && !diagonal && !is_leaf_bound(vb.ub)) { // a non-diagonal var can only be a subtype of a diagonal var if its // upper bound is concrete. @@ -1559,7 +1557,7 @@ static jl_value_t *intersect_unionall_(jl_value_t *t, jl_unionall_t *u, jl_stenv else { res = intersect(u->body, t, e, param); } - vb->concrete |= (!vb->occurs_inv && vb->occurs_cov > 1 && is_leaf_typevar((jl_value_t*)u->var)); + vb->concrete |= (!vb->occurs_inv && vb->occurs_cov > 1 && is_leaf_typevar(u->var)); // handle the "diagonal dispatch" rule, which says that a type var occurring more // than once, and only in covariant position, is constrained to concrete types. E.g. @@ -2027,11 +2025,11 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa if (ii == jl_bottom_type) return jl_bottom_type; if (jl_is_typevar(xp1)) { jl_varbinding_t *xb = lookup(e, (jl_tvar_t*)xp1); - if (xb && is_leaf_typevar((jl_value_t*)xb->var)) xb->concrete = 1; + if (xb && is_leaf_typevar(xb->var)) xb->concrete = 1; } if (jl_is_typevar(yp1)) { jl_varbinding_t *yb = lookup(e, (jl_tvar_t*)yp1); - if (yb && is_leaf_typevar((jl_value_t*)yb->var)) yb->concrete = 1; + if (yb && is_leaf_typevar(yb->var)) yb->concrete = 1; } JL_GC_PUSH2(&ii, &i2); // Vararg{T,N} <: Vararg{T2,N2}; equate N and N2 diff --git a/test/subtype.jl b/test/subtype.jl index 69150ee6fb34c..f62418aa57e67 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -86,7 +86,7 @@ function test_diagonal() @test !issub(Tuple{Integer,Integer}, @UnionAll T Tuple{T,T}) @test issub(Tuple{Integer,Int}, (@UnionAll T @UnionAll S<:T Tuple{T,S})) @test issub(Tuple{Integer,Int}, (@UnionAll T @UnionAll T<:S<:T Tuple{T,S})) - @test !issub(Tuple{Integer,Int,Int}, (@UnionAll T @UnionAll T<:S<:T Tuple{T,S,S})) + @test issub(Tuple{Integer,Int,Int}, (@UnionAll T @UnionAll T<:S<:T Tuple{T,S,S})) @test issub_strict((@UnionAll R Tuple{R,R}), (@UnionAll T @UnionAll S Tuple{T,S})) @@ -132,6 +132,8 @@ function test_diagonal() @test issub(Tuple{Tuple{T, T} where T>:Int}, Tuple{Tuple{T, T} where T>:Int}) @test issub(Tuple{Tuple{T, T} where T>:Int}, Tuple{Tuple{T, T}} where T>:Int) @test issub(Tuple{Tuple{T, T}} where T>:Int, Tuple{Tuple{T, T} where T>:Int}) + @test issub(Vector{Tuple{T, T} where Number<:T<:Number}, + Vector{Tuple{Number, Number}}) end # level 3: UnionAll @@ -1259,3 +1261,12 @@ end let (t, e) = intersection_env(Tuple{Union{Int,Int8}}, Tuple{T} where T) @test e[1] isa TypeVar end + +# issue #26453 +@test (Tuple{A,A,Number} where A>:Number) <: Tuple{T,T,S} where T>:S where S +@test (Tuple{T,T} where {S,T>:S}) == (Tuple{T,T} where {S,T>:S}) +f26453(x::T,y::T) where {S,T>:S} = 0 +@test f26453(1,2) == 0 +@test f26453(1,"") == 0 +g26453(x::T,y::T) where {S,T>:S} = T +@test_throws UndefVarError(:T) g26453(1,1)