mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fixed finding variables defined in the upper proc failed
If no new variable was defined in the `eval` method, the variable was hidden from the nested `eval` method. ```ruby a = 1 p eval %(b = 2; eval %(a)) # => 1 (good) p eval %(eval %(a)) # => undefined method 'a' (NoMethodError) ``` This issue has occurred since mruby 3.0.0.
This commit is contained in:
@@ -807,10 +807,12 @@ search_upvar(codegen_scope *s, mrb_sym id, int *idx)
|
||||
int i;
|
||||
|
||||
const mrb_sym *v = ir->lv;
|
||||
for (i=1; n > 1; n--, v++, i++) {
|
||||
if (*v == id) {
|
||||
*idx = i;
|
||||
return lv - 1;
|
||||
if (v) {
|
||||
for (i=1; n > 1; n--, v++, i++) {
|
||||
if (*v == id) {
|
||||
*idx = i;
|
||||
return lv - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MRB_PROC_SCOPE_P(u)) break;
|
||||
|
||||
@@ -286,9 +286,10 @@ local_var_p(parser_state *p, mrb_sym sym)
|
||||
const mrb_sym *v = ir->lv;
|
||||
int i;
|
||||
|
||||
if (!v) break;
|
||||
for (i=0; i+1 < ir->nlocals; i++) {
|
||||
if (v[i] == sym) return TRUE;
|
||||
if (v) {
|
||||
for (i=0; i+1 < ir->nlocals; i++) {
|
||||
if (v[i] == sym) return TRUE;
|
||||
}
|
||||
}
|
||||
if (MRB_PROC_SCOPE_P(u)) break;
|
||||
u = u->upper;
|
||||
|
||||
+995
-994
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user