diff options
author | Delio Brignoli <brignoli.delio@gmail.com> | 2015-09-17 12:07:06 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-09-23 11:37:00 +0100 |
commit | e6978a4e26a17ef473e2aad78662d3bf29638578 (patch) | |
tree | 3c42f0a50a150b8f140c41211308c46562c28900 /py/compile.c | |
parent | 587914169cc6ff7f0513bd14c42dcbb275bf77bd (diff) | |
download | micropython-e6978a4e26a17ef473e2aad78662d3bf29638578.tar.gz micropython-e6978a4e26a17ef473e2aad78662d3bf29638578.zip |
py: Fix call args when a stararg is followed by keyword args.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c index 34f377fb0c..9ac37c6d95 100644 --- a/py/compile.c +++ b/py/compile.c @@ -2203,6 +2203,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar int n_positional = n_positional_extra; uint n_keyword = 0; uint star_flags = 0; + mp_parse_node_struct_t *star_args_node = NULL, *dblstar_args_node = NULL; for (int i = 0; i < n_args; i++) { if (MP_PARSE_NODE_IS_STRUCT(args[i])) { mp_parse_node_struct_t *pns_arg = (mp_parse_node_struct_t*)args[i]; @@ -2212,14 +2213,14 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar return; } star_flags |= MP_EMIT_STAR_FLAG_SINGLE; - compile_node(comp, pns_arg->nodes[0]); + star_args_node = pns_arg; } else if (MP_PARSE_NODE_STRUCT_KIND(pns_arg) == PN_arglist_dbl_star) { if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) { compile_syntax_error(comp, (mp_parse_node_t)pns_arg, "can't have multiple **x"); return; } star_flags |= MP_EMIT_STAR_FLAG_DOUBLE; - compile_node(comp, pns_arg->nodes[0]); + dblstar_args_node = pns_arg; } else if (MP_PARSE_NODE_STRUCT_KIND(pns_arg) == PN_argument) { assert(MP_PARSE_NODE_IS_STRUCT(pns_arg->nodes[1])); // should always be mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t*)pns_arg->nodes[1]; @@ -2250,6 +2251,14 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar } } + // compile the star/double-star arguments if we had them + if (star_args_node != NULL) { + compile_node(comp, star_args_node->nodes[0]); + } + if (dblstar_args_node != NULL) { + compile_node(comp, dblstar_args_node->nodes[0]); + } + // emit the function/method call if (is_method_call) { EMIT_ARG(call_method, n_positional, n_keyword, star_flags); |