diff options
author | Damien George <damien.p.george@gmail.com> | 2015-09-07 16:55:02 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-09-07 16:55:02 +0100 |
commit | 558a016e2c02157aa610ae55e72e14a18e43abc5 (patch) | |
tree | d4152f14ff7baa9a6759bbd407a45e14e8c640f3 /py/compile.c | |
parent | 3a2171e4061f3a6e3f00c28edf78ff9473355887 (diff) |
py/compile: Refine SyntaxError for repeated use of global/nonlocal.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/py/compile.c b/py/compile.c index 8580c8ce4..34f377fb0 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1355,9 +1355,8 @@ STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, qstr qst) { bool added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qst, &added); - if (!added) { - // TODO this is not compliant with CPython - compile_syntax_error(comp, pn, "identifier already used"); + if (!added && id_info->kind != ID_INFO_KIND_GLOBAL_EXPLICIT) { + compile_syntax_error(comp, pn, "identifier redefined as global"); return; } id_info->kind = ID_INFO_KIND_GLOBAL_EXPLICIT; @@ -1382,9 +1381,8 @@ STATIC void compile_global_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, qstr qst) { bool added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qst, &added); - if (!added) { - // TODO this is not compliant with CPython - compile_syntax_error(comp, pn, "identifier already used"); + if (!added && id_info->kind != ID_INFO_KIND_FREE) { + compile_syntax_error(comp, pn, "identifier redefined as nonlocal"); return; } id_info_t *id_info2 = scope_find_local_in_parent(comp->scope_cur, qst); |