Commit fc80e4b6 authored by dearblue's avatar dearblue

Get local variable names from orphan block; ref #3710

parent d5cca2bd
...@@ -146,7 +146,7 @@ mrb_local_variables(mrb_state *mrb, mrb_value self) ...@@ -146,7 +146,7 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
while (proc) { while (proc) {
if (MRB_PROC_CFUNC_P(proc)) break; if (MRB_PROC_CFUNC_P(proc)) break;
irep = proc->body.irep; irep = proc->body.irep;
if (!irep->lv) break; if (irep->lv) {
for (i = 0; i + 1 < irep->nlocals; ++i) { for (i = 0; i + 1 < irep->nlocals; ++i) {
if (irep->lv[i].name) { if (irep->lv[i].name) {
mrb_sym sym = irep->lv[i].name; mrb_sym sym = irep->lv[i].name;
...@@ -160,10 +160,9 @@ mrb_local_variables(mrb_state *mrb, mrb_value self) ...@@ -160,10 +160,9 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
} }
} }
} }
if (!MRB_PROC_ENV_P(proc)) break; }
if (MRB_PROC_SCOPE_P(proc)) break;
proc = proc->upper; proc = proc->upper;
//if (MRB_PROC_SCOPE_P(proc)) break;
if (!proc->c) break;
} }
return mrb_hash_keys(mrb, vars); return mrb_hash_keys(mrb, vars);
......
...@@ -114,6 +114,15 @@ assert('Kernel.local_variables', '15.3.1.2.7') do ...@@ -114,6 +114,15 @@ assert('Kernel.local_variables', '15.3.1.2.7') do
# Kernel#local_variables: 15.3.1.3.28 # Kernel#local_variables: 15.3.1.3.28
local_variables.sort local_variables.sort
}.call(-1, -2) }.call(-1, -2)
a = Object.new
def a.hoge(vars, *, **)
Proc.new {
x, y = 1, 2
local_variables.sort
}
end
assert_equal([:vars, :x, :y]) { a.hoge(0).call }
end end
assert('Kernel#define_singleton_method') do assert('Kernel#define_singleton_method') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment