diff options
| author | dearblue <[email protected]> | 2021-06-26 11:00:32 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-06-26 11:00:32 +0900 |
| commit | 52b29f41a3f8364712f14aad69186eb69b825b10 (patch) | |
| tree | 6c87903412143d19b2ea0b5e2608038c5ced21c0 /mrbgems/mruby-compiler/core/parse.y | |
| parent | 5fc301f07d0ce26ab93ff237d15fa81894c9f1d6 (diff) | |
| download | mruby-52b29f41a3f8364712f14aad69186eb69b825b10.tar.gz mruby-52b29f41a3f8364712f14aad69186eb69b825b10.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 8e68fa21a..96615e3bb 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -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; |
