diff options
author | Damien George <damien.p.george@gmail.com> | 2015-03-01 12:04:05 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-03-01 12:04:05 +0000 |
commit | 62a3a287d9aca9a8552671257c5b989c32a97d6f (patch) | |
tree | 3819a844888dc9bebd9e4173000368b0154f25dc /py | |
parent | d01060241a2102878a2b6ff270323e7d278f0af8 (diff) | |
download | micropython-62a3a287d9aca9a8552671257c5b989c32a97d6f.tar.gz micropython-62a3a287d9aca9a8552671257c5b989c32a97d6f.zip |
py: Set compiler scope before folding constants so error messages work.
Addresses issue #1140.
Diffstat (limited to 'py')
-rw-r--r-- | py/compile.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/py/compile.c b/py/compile.c index 41e2610c04..0386b956aa 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3605,15 +3605,16 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is comp->is_repl = is_repl; comp->compile_error = MP_OBJ_NULL; - // optimise constants + // create the module scope + scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, pn, emit_opt); + + // optimise constants (scope must be set for error messages to work) + comp->scope_cur = module_scope; mp_map_t consts; mp_map_init(&consts, 0); - pn = fold_constants(comp, pn, &consts); + module_scope->pn = fold_constants(comp, module_scope->pn, &consts); mp_map_deinit(&consts); - // set the outer scope - scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, pn, emit_opt); - // compile pass 1 comp->emit = emit_pass1_new(); comp->emit_method_table = &emit_pass1_method_table; @@ -3764,7 +3765,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is #endif // !MICROPY_EMIT_CPYTHON // free the parse tree - mp_parse_node_free(pn); + mp_parse_node_free(module_scope->pn); // free the scopes mp_raw_code_t *outer_raw_code = module_scope->raw_code; |