rescue NameError from class variable access like `@@foo ||= 42`; fix #3138

parent 643d967b
...@@ -1221,13 +1221,12 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1221,13 +1221,12 @@ codegen(codegen_scope *s, node *tree, int val)
int onerr, noexc, exend, pos1, pos2, tmp; int onerr, noexc, exend, pos1, pos2, tmp;
struct loopinfo *lp; struct loopinfo *lp;
if (tree->car == NULL) return;
onerr = genop(s, MKOP_Bx(OP_ONERR, 0)); onerr = genop(s, MKOP_Bx(OP_ONERR, 0));
lp = loop_push(s, LOOP_BEGIN); lp = loop_push(s, LOOP_BEGIN);
lp->pc1 = onerr; lp->pc1 = onerr;
if (tree->car) { codegen(s, tree->car, VAL);
codegen(s, tree->car, val); pop();
if (val) pop();
}
lp->type = LOOP_RESCUE; lp->type = LOOP_RESCUE;
noexc = genop(s, MKOP_Bx(OP_JMP, 0)); noexc = genop(s, MKOP_Bx(OP_JMP, 0));
dispatch(s, onerr); dispatch(s, onerr);
...@@ -1709,7 +1708,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1709,7 +1708,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop(); pop();
gen_assignment(s, tree->car, cursp(), val); gen_assignment(s, tree->car, cursp(), val);
dispatch(s, pos); dispatch(s, pos);
break; return;
} }
codegen(s, tree->cdr->cdr->car, VAL); codegen(s, tree->cdr->cdr->car, VAL);
push(); pop(); push(); pop();
......
...@@ -707,7 +707,13 @@ new_masgn(parser_state *p, node *a, node *b) ...@@ -707,7 +707,13 @@ new_masgn(parser_state *p, node *a, node *b)
static node* static node*
new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b) new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
{ {
return list4((node*)NODE_OP_ASGN, a, nsym(op), b); if (op == mrb_intern_lit(p->mrb, "||") && (intptr_t)a->car == NODE_CVAR) {
return new_rescue(p, a, list1(list3(list1(new_cvar(p, mrb_intern_lit(p->mrb, "NameError"))),
0, new_asgn(p, a, b))), NULL);
}
else {
return list4((node*)NODE_OP_ASGN, a, nsym(op), b);
}
} }
/* (:int . i) */ /* (:int . i) */
......
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