diff options
author | Damien George <damien.p.george@gmail.com> | 2018-10-26 16:48:07 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-10-28 00:33:08 +1100 |
commit | 9201f46cc8e92231f0f6c92e4d56befbc150f72c (patch) | |
tree | 425eeb6f9031a94acf2b79cb56a0a35a902da173 /py/scope.c | |
parent | c2074e7b66a042492604fbf9ea80b71cdf848e93 (diff) |
py/compile: Fix case of eager implicit conversion of local to nonlocal.
This ensures that implicit variables are only converted to implicit
closed-over variables (nonlocals) at the very end of the function scope.
If variables are closed-over when first used (read from, as was done prior
to this commit) then this can be incorrect because the variable may be
assigned to later on in the function which means they are just a plain
local, not closed over.
Fixes issue #4272.
Diffstat (limited to 'py/scope.c')
-rw-r--r-- | py/scope.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/py/scope.c b/py/scope.c index 1a6ae7b8a..8adb85b80 100644 --- a/py/scope.c +++ b/py/scope.c @@ -130,21 +130,19 @@ STATIC void scope_close_over_in_parents(scope_t *scope, qstr qst) { } } -void scope_find_local_and_close_over(scope_t *scope, id_info_t *id, qstr qst) { +void scope_check_to_close_over(scope_t *scope, id_info_t *id) { if (scope->parent != NULL) { for (scope_t *s = scope->parent; s->parent != NULL; s = s->parent) { - id_info_t *id2 = scope_find(s, qst); + id_info_t *id2 = scope_find(s, id->qst); if (id2 != NULL) { if (id2->kind == ID_INFO_KIND_LOCAL || id2->kind == ID_INFO_KIND_CELL || id2->kind == ID_INFO_KIND_FREE) { id->kind = ID_INFO_KIND_FREE; - scope_close_over_in_parents(scope, qst); - return; + scope_close_over_in_parents(scope, id->qst); } break; } } } - id->kind = ID_INFO_KIND_GLOBAL_IMPLICIT; } #endif // MICROPY_ENABLE_COMPILER |