summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler/core/parse.y
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-03-21 03:49:08 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-03-21 03:49:08 +0900
commita02acf2635d6a69c5c88ad5a67c9a8e17b2a951d (patch)
tree27ade19fb38a447fe64b01fb1f1280f2fcb16002 /mrbgems/mruby-compiler/core/parse.y
parent643d967b101586c5946be4394a1f6bd9f0ef1f2b (diff)
downloadmruby-a02acf2635d6a69c5c88ad5a67c9a8e17b2a951d.tar.gz
mruby-a02acf2635d6a69c5c88ad5a67c9a8e17b2a951d.zip
rescue NameError from class variable access like `@@foo ||= 42`; fix #3138
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
-rw-r--r--mrbgems/mruby-compiler/core/parse.y8
1 files changed, 7 insertions, 1 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 434e16ece..fdc179a30 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -707,7 +707,13 @@ new_masgn(parser_state *p, node *a, node *b)
static node*
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) */