diff --git a/src/gf.c b/src/gf.c index c01da4554ef1e..c8f38f44f0f61 100644 --- a/src/gf.c +++ b/src/gf.c @@ -415,7 +415,7 @@ JL_DLLEXPORT void jl_set_typeinf_func(jl_value_t *f) static int very_general_type(jl_value_t *t) { - return (t == (jl_value_t*)jl_any_type || t == (jl_value_t*)jl_type_type || jl_types_equal(t, (jl_value_t*)jl_type_type)); + return (t == (jl_value_t*)jl_any_type || jl_types_equal(t, (jl_value_t*)jl_type_type)); } jl_value_t *jl_nth_slot_type(jl_value_t *sig, size_t i) @@ -528,17 +528,17 @@ static void jl_compilation_sig( } } - if (jl_types_equal(elt, (jl_value_t*)jl_typetype_type)) { + if (jl_types_equal(elt, (jl_value_t*)jl_typetype_type)) { // elt == Type{T} where T // not triggered for isdispatchtuple(tt), this attempts to handle // some cases of adapting a random signature into a compilation signature } - else if (!jl_is_datatype(elt) && !jl_has_empty_intersection((jl_value_t*)jl_type_type, elt)) { + else if (!jl_is_datatype(elt) && jl_subtype(elt, (jl_value_t*)jl_type_type)) { // elt <: Type{T} // not triggered for isdispatchtuple(tt), this attempts to handle // some cases of adapting a random signature into a compilation signature if (!*newparams) *newparams = jl_svec_copy(tt->parameters); jl_svecset(*newparams, i, jl_typetype_type); } - else if (jl_is_type_type(elt)) { + else if (jl_is_type_type(elt)) { // elt isa Type{T} if (very_general_type(decl_i)) { /* here's a fairly simple heuristic: if this argument slot's diff --git a/test/core.jl b/test/core.jl index 3d561b37948b9..f26e633f35b15 100644 --- a/test/core.jl +++ b/test/core.jl @@ -6894,3 +6894,24 @@ function foo31357(b::Bool) end @test foo31357(true) == 12345 @test foo31357(false) == 12345 + +# Issue #31406 +abstract type Shape31406 end +struct ValueOf31406 <: Shape31406 + ty::Type +end +struct TupleOf31406 <: Shape31406 + cols::Vector{Shape31406} +end +TupleOf31406(cols::Union{Shape31406,Type}...) = TupleOf31406(collect(Shape31406, cols)) +@test (TupleOf31406(ValueOf31406(Int64), ValueOf31406(Float64))::TupleOf31406).cols == + Shape31406[ValueOf31406(Int64), ValueOf31406(Float64)] +@test try + TupleOf31406(ValueOf31406(Int64), Float64) + false + catch ex + if !(ex isa MethodError && ex.f === convert && ex.args == (Shape31406, Float64)) + rethrow(ex) + end + true + end