Skip to content

Commit

Permalink
Merge pull request JuliaLang#11151 from JuliaLang/ob/fixvainv
Browse files Browse the repository at this point in the history
Fix invoke for vararg methods.
  • Loading branch information
carnaval committed May 7, 2015
2 parents de6e41f + b61f46f commit cd2c363
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,13 @@ static jl_function_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_datatype_t *tt,
func = m->func;
if (m->isstaged)
func = jl_instantiate_staged(m,tt,env);
JL_GC_POP();
if (!cache)
if (!cache) {
JL_GC_POP();
return func;
return cache_method(mt, tt, func, m->sig, jl_emptysvec, m->isstaged);
}
jl_function_t *res = cache_method(mt, tt, func, m->sig, jl_emptysvec, m->isstaged);
JL_GC_POP();
return res;
}
JL_GC_POP();
return jl_bottom_func;
Expand Down Expand Up @@ -1383,6 +1386,15 @@ static void remove_conflicting(jl_methlist_t **pl, jl_value_t *type)
}
}

static void update_max_args(jl_methtable_t *mt, jl_tupletype_t *type)
{
size_t na = jl_nparams(type);
if (jl_is_va_tuple(type))
na--;
if (na > mt->max_args)
mt->max_args = na;
}

jl_methlist_t *jl_method_table_insert(jl_methtable_t *mt, jl_tupletype_t *type,
jl_function_t *method, jl_svec_t *tvars,
int8_t isstaged)
Expand Down Expand Up @@ -1412,12 +1424,7 @@ jl_methlist_t *jl_method_table_insert(jl_methtable_t *mt, jl_tupletype_t *type,
}
}
}
// update max_args
size_t na = jl_nparams(type);
if (jl_is_va_tuple(type))
na--;
if (na > mt->max_args)
mt->max_args = na;
update_max_args(mt, type);
JL_SIGATOMIC_END();
return ml;
}
Expand Down Expand Up @@ -1825,16 +1832,15 @@ jl_value_t *jl_gf_invoke(jl_function_t *gf, jl_tupletype_t *types,
jl_tupletype_t *newsig=NULL;
jl_tupletype_t *tt=NULL;
JL_GC_PUSH3(&tpenv, &newsig, &tt);

tt = arg_type_tuple(args, nargs);
if (m->invokes == (void*)jl_nothing) {
m->invokes = new_method_table(mt->name);
gc_wb(m, m->invokes);
update_max_args(m->invokes, tt);
// this private method table has just this one definition
jl_method_list_insert(&m->invokes->defs,m->sig,m->func,m->tvars,0,0,(jl_value_t*)m->invokes);
}

tt = arg_type_tuple(args, nargs);

newsig = m->sig;

if (m->tvars != jl_emptysvec) {
Expand Down
4 changes: 4 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2812,3 +2812,7 @@ f10995(T::TupleType10978) = (while false; end; @assert isa(T, TupleType10978))
g10995(x) = f10995(typeof(x))
g10995((1, 2))
@test g10995(UInt8) === nothing

# issue #11149
@noinline f11149(a,b,args...) = (a,b,args...)
@test f11149(1,2,3) == invoke(f11149, Tuple{Int,Int,Int}, 1,2,3)

0 comments on commit cd2c363

Please sign in to comment.