From 4f17558e4c71908e8ba40d24e37bdacd5e2f2e5e Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 23 Sep 2019 12:31:11 -0400 Subject: [PATCH] add a subtyping fast path for tuple of Unions <: Vararg (#33353) fixes #33337 --- src/subtype.c | 4 ++++ test/subtype.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/subtype.c b/src/subtype.c index 6bff58224884e..ec969ef3b80ea 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -1049,6 +1049,10 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_ yi = jl_tparam0(jl_unwrap_unionall(env->vty)); if (!env->vvx && yi == (jl_value_t*)jl_any_type) goto done; // if y ends in `Vararg{Any}` skip checking everything + // var T in Vararg{T} is diagonal; an abstract type can't be a subtype of it, + // so avoid exponential blowup when xi is a Union. + if (jl_is_typevar(yi) && jl_is_uniontype(xi) && !jl_has_free_typevars(xi)) + return 0; } if (xi == env->lastx && ((yi == env->lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) || diff --git a/test/subtype.jl b/test/subtype.jl index 5a3b945d86db8..260b3cfaa9453 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1676,3 +1676,7 @@ c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str @testintersect(Tuple{Pair{Int, DataType}, Any}, Tuple{Pair{A, B} where B<:Type, Int} where A, Tuple{Pair{Int, DataType}, Int}) + +# issue #33337 +@test !issub(Tuple{Type{T}, T} where T<:NTuple{30, Union{Nothing, Ref}}, + Tuple{Type{Tuple{Vararg{V, N} where N}}, Tuple{Vararg{V, N} where N}} where V)