From ac8ba729a61dbc4c044adddb90dfda91786b643f Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 30 Oct 2014 23:34:07 -0400 Subject: [PATCH] fix #8861: invoke for overloaded call --- src/builtins.c | 24 +++++++++++++++++++++--- test/core.jl | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index dd987e1ad1bf6..41764ee32bde2 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -892,10 +892,28 @@ JL_CALLABLE(jl_f_applicable) JL_CALLABLE(jl_f_invoke) { JL_NARGSV(invoke, 2); - JL_TYPECHK(invoke, function, args[0]); - if (!jl_is_gf(args[0])) - jl_error("invoke: not a generic function"); JL_TYPECHK(invoke, tuple, args[1]); + if (!jl_is_gf(args[0])) { + if (jl_is_function(args[0])) + jl_error("invoke: not a generic function"); + jl_tuple_t *tup = jl_alloc_tuple_uninit(1 + jl_tuple_len(args[1])); + jl_tupleset(tup, 0, (jl_is_datatype(args[0]) + ? (jl_value_t*) jl_wrap_Type(args[0]) + : jl_typeof(args[0]))); + for(size_t i=0; i < jl_tuple_len(args[1]); i++) { + jl_tupleset(tup, i+1, jl_tupleref(args[1],i)); + } + jl_value_t **newargs = (jl_value_t**) alloca(sizeof(jl_value_t*) + * (nargs + 1)); + newargs[0] = (jl_value_t*) jl_module_call_func(jl_current_module); + newargs[1] = (jl_value_t*) tup; + newargs[2] = args[0]; + for(uint32_t j=2; j < nargs; ++j) { + newargs[j+1] = args[j]; + } + args = newargs; + nargs++; + } jl_check_type_tuple((jl_tuple_t*)args[1], jl_gf_name(args[0]), "invoke"); if (!jl_tuple_subtype(&args[2], nargs-2, &jl_tupleref(args[1],0), jl_tuple_len(args[1]), 1)) diff --git a/test/core.jl b/test/core.jl index f18e4a7d512dd..ca4041c7fa624 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1928,3 +1928,7 @@ type ConcreteThing{T<:FloatingPoint,N} <: AbstractThing{T,N} end @test typeintersect(AbstractThing{TypeVar(:T,true),2}, ConcreteThing) == ConcreteThing{TypeVar(:T,FloatingPoint),2} + +# issue #8712 +type Issue8712; end +@test isa(invoke(Issue8712, ()), Issue8712)