diff options
author | Damien George <damien.p.george@gmail.com> | 2015-11-23 16:50:42 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-11-23 16:50:42 +0000 |
commit | 9a56912ad16065c8fc3670c8d493f922bc54e5b1 (patch) | |
tree | ae5ca9edae11e43451d065ebdbabfe4184546672 /py/compile.c | |
parent | 0e3f29cc9973dc3c522941858f1f0fb4c6b2cba0 (diff) |
py/compile: Do proper checking of * and ** in function definition.
This patch checks that there is only one *, and that ** is last in the
arg list.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/py/compile.c b/py/compile.c index e15e7b3b8..4fcd64f29 100644 --- a/py/compile.c +++ b/py/compile.c @@ -2505,7 +2505,12 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { } STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) { - // TODO verify that *k and **k are last etc + // check that **kw is last + if ((comp->scope_cur->scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) { + compile_syntax_error(comp, pn, "invalid syntax"); + return; + } + qstr param_name = MP_QSTR_NULL; uint param_flag = ID_FLAG_IS_PARAM; if (MP_PARSE_NODE_IS_ID(pn)) { @@ -2530,6 +2535,11 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn comp->scope_cur->num_pos_args += 1; } } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == pn_star) { + if (comp->have_star) { + // more than one star + compile_syntax_error(comp, pn, "invalid syntax"); + return; + } comp->have_star = true; param_flag = ID_FLAG_IS_PARAM | ID_FLAG_IS_STAR_PARAM; if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { |