From f731c38bf84604443f0760b114957e40f2b10fa2 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 8 Mar 2022 15:31:54 -0500 Subject: [PATCH] ensure invoke kwargs work on Types (#44464) Fix #44227 --- src/builtins.c | 4 ++-- test/core.jl | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index ca2f56adaf6d8..11da13285e9ca 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1286,7 +1286,7 @@ JL_CALLABLE(jl_f_invoke_kwsorter) if (nt < jl_page_size/sizeof(jl_value_t*)) { jl_value_t **types = (jl_value_t**)alloca(nt*sizeof(jl_value_t*)); types[0] = (jl_value_t*)jl_namedtuple_type; - types[1] = jl_typeof(func); + types[1] = jl_is_type(func) ? (jl_value_t*)jl_wrap_Type(func) : jl_typeof(func); for (i = 2; i < nt; i++) types[i] = jl_tparam(argtypes, i - 2); argtypes = (jl_value_t*)jl_apply_tuple_type_v(types, nt); @@ -1295,7 +1295,7 @@ JL_CALLABLE(jl_f_invoke_kwsorter) jl_svec_t *types = jl_alloc_svec_uninit(nt); JL_GC_PUSH1(&types); jl_svecset(types, 0, jl_namedtuple_type); - jl_svecset(types, 1, jl_typeof(func)); + jl_svecset(types, 1, jl_is_type(func) ? (jl_value_t*)jl_wrap_Type(func) : jl_typeof(func)); for (i = 2; i < nt; i++) jl_svecset(types, i, jl_tparam(argtypes, i - 2)); argtypes = (jl_value_t*)jl_apply_tuple_type(types); diff --git a/test/core.jl b/test/core.jl index 6dbd8f3d9fa0e..93ba97df60420 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1524,6 +1524,12 @@ let @test invoke(i2169, Tuple{Array}, Int8[1]) === Int8(-128) end +# issue #44227 +struct F{T} end +F{Int32}(; y=1) = 1 +F{Int64}(; y=1) = invoke(F{Int32}, Tuple{}; y) +@test F{Int64}() === 1 + # issue #2365 mutable struct B2365{T} v::Union{T, Nothing}