Skip to content

Commit cd2c363

Browse files
committed
Merge pull request #11151 from JuliaLang/ob/fixvainv
Fix invoke for vararg methods.
2 parents de6e41f + b61f46f commit cd2c363

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/gf.c

+18-12
Original file line numberDiff line numberDiff line change
@@ -1066,10 +1066,13 @@ static jl_function_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_datatype_t *tt,
10661066
func = m->func;
10671067
if (m->isstaged)
10681068
func = jl_instantiate_staged(m,tt,env);
1069-
JL_GC_POP();
1070-
if (!cache)
1069+
if (!cache) {
1070+
JL_GC_POP();
10711071
return func;
1072-
return cache_method(mt, tt, func, m->sig, jl_emptysvec, m->isstaged);
1072+
}
1073+
jl_function_t *res = cache_method(mt, tt, func, m->sig, jl_emptysvec, m->isstaged);
1074+
JL_GC_POP();
1075+
return res;
10731076
}
10741077
JL_GC_POP();
10751078
return jl_bottom_func;
@@ -1383,6 +1386,15 @@ static void remove_conflicting(jl_methlist_t **pl, jl_value_t *type)
13831386
}
13841387
}
13851388

1389+
static void update_max_args(jl_methtable_t *mt, jl_tupletype_t *type)
1390+
{
1391+
size_t na = jl_nparams(type);
1392+
if (jl_is_va_tuple(type))
1393+
na--;
1394+
if (na > mt->max_args)
1395+
mt->max_args = na;
1396+
}
1397+
13861398
jl_methlist_t *jl_method_table_insert(jl_methtable_t *mt, jl_tupletype_t *type,
13871399
jl_function_t *method, jl_svec_t *tvars,
13881400
int8_t isstaged)
@@ -1412,12 +1424,7 @@ jl_methlist_t *jl_method_table_insert(jl_methtable_t *mt, jl_tupletype_t *type,
14121424
}
14131425
}
14141426
}
1415-
// update max_args
1416-
size_t na = jl_nparams(type);
1417-
if (jl_is_va_tuple(type))
1418-
na--;
1419-
if (na > mt->max_args)
1420-
mt->max_args = na;
1427+
update_max_args(mt, type);
14211428
JL_SIGATOMIC_END();
14221429
return ml;
14231430
}
@@ -1825,16 +1832,15 @@ jl_value_t *jl_gf_invoke(jl_function_t *gf, jl_tupletype_t *types,
18251832
jl_tupletype_t *newsig=NULL;
18261833
jl_tupletype_t *tt=NULL;
18271834
JL_GC_PUSH3(&tpenv, &newsig, &tt);
1828-
1835+
tt = arg_type_tuple(args, nargs);
18291836
if (m->invokes == (void*)jl_nothing) {
18301837
m->invokes = new_method_table(mt->name);
18311838
gc_wb(m, m->invokes);
1839+
update_max_args(m->invokes, tt);
18321840
// this private method table has just this one definition
18331841
jl_method_list_insert(&m->invokes->defs,m->sig,m->func,m->tvars,0,0,(jl_value_t*)m->invokes);
18341842
}
18351843

1836-
tt = arg_type_tuple(args, nargs);
1837-
18381844
newsig = m->sig;
18391845

18401846
if (m->tvars != jl_emptysvec) {

test/core.jl

+4
Original file line numberDiff line numberDiff line change
@@ -2812,3 +2812,7 @@ f10995(T::TupleType10978) = (while false; end; @assert isa(T, TupleType10978))
28122812
g10995(x) = f10995(typeof(x))
28132813
g10995((1, 2))
28142814
@test g10995(UInt8) === nothing
2815+
2816+
# issue #11149
2817+
@noinline f11149(a,b,args...) = (a,b,args...)
2818+
@test f11149(1,2,3) == invoke(f11149, Tuple{Int,Int,Int}, 1,2,3)

0 commit comments

Comments
 (0)