diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-08-11 16:27:14 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-08-11 16:27:14 +0900 |
| commit | 90e8ce5c30465e3b7db782900424c8f6ea117776 (patch) | |
| tree | 75b644d71e739f11c719e4b22dc7c4b07ef652d5 | |
| parent | 7a7fac8412e980602fc3d660425109c21de91126 (diff) | |
| download | mruby-90e8ce5c30465e3b7db782900424c8f6ea117776.tar.gz mruby-90e8ce5c30465e3b7db782900424c8f6ea117776.zip | |
parse.y: rescue modifiers for OP_ASGN should protect rhs only
reported in [Bug:12402] in bugs.ruby-lang.org fixed in CRuby 2.4
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 1ddf483a8..b474295ed 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -310,6 +310,12 @@ new_rescue(parser_state *p, node *body, node *resq, node *els) return list4((node*)NODE_RESCUE, body, resq, els); } +static node* +new_mod_rescue(parser_state *p, node *body, node *resq) +{ + return new_rescue(p, body, list1(list3(0, 0, resq)), 0); +} + /* (:ensure body ensure) */ static node* new_ensure(parser_state *p, node *a, node *b) @@ -1300,7 +1306,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym } | stmt modifier_rescue stmt { - $$ = new_rescue(p, $1, list1(list3(0, 0, $3)), 0); + $$ = new_mod_rescue(p, $1, $3); } | keyword_END '{' compstmt '}' { @@ -1316,18 +1322,34 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym { $$ = new_op_asgn(p, $1, $2, $3); } + | var_lhs tOP_ASGN command_call modifier_rescue stmt + { + $$ = new_op_asgn(p, $1, $2, new_mod_rescue(p, $3, $5)); + } | primary_value '[' opt_call_args rbracket tOP_ASGN command_call { $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); } + | primary_value '[' opt_call_args rbracket tOP_ASGN command_call modifier_rescue stmt + { + $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, new_mod_rescue(p, $6, $8)); + } | primary_value call_op tIDENTIFIER tOP_ASGN command_call { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } + | primary_value call_op tIDENTIFIER tOP_ASGN command_call modifier_rescue stmt + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); + } | primary_value call_op tCONSTANT tOP_ASGN command_call { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } + | primary_value call_op tCONSTANT tOP_ASGN command_call modifier_rescue stmt + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); + } | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call { yyerror(p, "constant re-assignment"); @@ -1337,11 +1359,20 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); } + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call modifier_rescue stmt + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, new_mod_rescue(p, $5, $7)); + } | backref tOP_ASGN command_call { backref_error(p, $1); $$ = new_begin(p, 0); } + | backref tOP_ASGN command_call modifier_rescue stmt + { + backref_error(p, $1); + $$ = new_begin(p, 0); + } | lhs '=' mrhs { $$ = new_asgn(p, $1, new_array(p, $3)); @@ -1361,6 +1392,10 @@ command_asgn : lhs '=' command_call { $$ = new_asgn(p, $1, $3); } + | lhs '=' command_call modifier_rescue stmt + { + $$ = new_asgn(p, $1, new_mod_rescue(p, $3, $5)); + } | lhs '=' command_asgn { $$ = new_asgn(p, $1, $3); @@ -1730,7 +1765,7 @@ arg : lhs '=' arg } | lhs '=' arg modifier_rescue arg { - $$ = new_asgn(p, $1, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); + $$ = new_asgn(p, $1, new_mod_rescue(p, $3, $5)); } | var_lhs tOP_ASGN arg { @@ -1738,39 +1773,70 @@ arg : lhs '=' arg } | var_lhs tOP_ASGN arg modifier_rescue arg { - $$ = new_op_asgn(p, $1, $2, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); + $$ = new_op_asgn(p, $1, $2, new_mod_rescue(p, $3, $5)); } | primary_value '[' opt_call_args rbracket tOP_ASGN arg { $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); } + | primary_value '[' opt_call_args rbracket tOP_ASGN arg modifier_rescue arg + { + $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, new_mod_rescue(p, $6, $8)); + } | primary_value call_op tIDENTIFIER tOP_ASGN arg { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } + | primary_value call_op tIDENTIFIER tOP_ASGN arg modifier_rescue arg + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); + } | primary_value call_op tCONSTANT tOP_ASGN arg { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } + | primary_value call_op tCONSTANT tOP_ASGN arg modifier_rescue arg + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); + } | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); } + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg modifier_rescue arg + { + $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, new_mod_rescue(p, $5, $7)); + } | primary_value tCOLON2 tCONSTANT tOP_ASGN arg { yyerror(p, "constant re-assignment"); $$ = new_begin(p, 0); } + | primary_value tCOLON2 tCONSTANT tOP_ASGN arg modifier_rescue arg + { + yyerror(p, "constant re-assignment"); + $$ = new_begin(p, 0); + } | tCOLON3 tCONSTANT tOP_ASGN arg { yyerror(p, "constant re-assignment"); $$ = new_begin(p, 0); } + | tCOLON3 tCONSTANT tOP_ASGN arg modifier_rescue arg + { + yyerror(p, "constant re-assignment"); + $$ = new_begin(p, 0); + } | backref tOP_ASGN arg { backref_error(p, $1); $$ = new_begin(p, 0); } + | backref tOP_ASGN arg modifier_rescue arg + { + backref_error(p, $1); + $$ = new_begin(p, 0); + } | arg tDOT2 arg { $$ = new_dot2(p, $1, $3); |
