diff --git a/src/subtype.c b/src/subtype.c index f0902cb1c8aa7..7ee1e64c84ee2 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -526,11 +526,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) @@ -636,7 +634,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. @@ -1564,7 +1562,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. @@ -2032,11 +2030,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 fcee63e81c2a1..486c1b4bc2477 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 @@ -1292,3 +1294,13 @@ abstract type Foo24748{T1,T2,T3} end @test !(Tuple{Type{Union{Missing, Float64}}, Type{Vector{Float64}}} <: Tuple{Type{T}, Type{Vector{T}}} where T) @test [[1],[missing]] isa Vector{Vector} @test [[missing],[1]] isa Vector{Vector} + +# 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) +@test issub_strict((Tuple{T,T} where T), (Tuple{T,T} where {S,T>:S}))