mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user