summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler/core/codegen.c
diff options
context:
space:
mode:
authordearblue <[email protected]>2021-06-26 11:00:32 +0900
committerdearblue <[email protected]>2021-06-26 11:00:32 +0900
commit52b29f41a3f8364712f14aad69186eb69b825b10 (patch)
tree6c87903412143d19b2ea0b5e2608038c5ced21c0 /mrbgems/mruby-compiler/core/codegen.c
parent5fc301f07d0ce26ab93ff237d15fa81894c9f1d6 (diff)
downloadmruby-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/codegen.c')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index be231ecfc..e429ffc0b 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -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;