register<nlocals may not have a local variable name (e.g. a block arg); fix #2258

parent 60051de4
......@@ -142,7 +142,9 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
}
ret = mrb_ary_new_capa(mrb, irep->nlocals - 1);
for (i = 0; i + 1 < irep->nlocals; ++i) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
if (irep->lv[i].name) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
}
}
if (proc->env) {
struct REnv *e = proc->env;
......@@ -152,7 +154,9 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
irep = mrb->c->cibase[e->cioff].proc->body.irep;
if (irep->lv) {
for (i = 0; i + 1 < irep->nlocals; ++i) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
if (irep->lv[i].name) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
}
}
}
}
......
......@@ -2503,7 +2503,12 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
p->irep->lv = (struct mrb_locals*)mrb_malloc(mrb, sizeof(struct mrb_locals) * (p->nlocals - 1));
for (i=0, n=lv; n; i++,n=n->cdr) {
p->irep->lv[i].name = lv_name(n);
p->irep->lv[i].r = lv_idx(p, lv_name(n));
if (lv_name(n)) {
p->irep->lv[i].r = lv_idx(p, lv_name(n));
}
else {
p->irep->lv[i].r = 0;
}
}
mrb_assert(i + 1 == p->nlocals);
}
......
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