1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix parsing of mutiple assignment with rescue modifier

Single assignment with rescue modifier applies rescue to the RHS:

  a = raise rescue 1 # a = (raise rescue 1)

Previously, multiple assignment with rescue modifier applied rescue
to the entire expression:

  a, b = raise rescue [1, 2] # (a, b = raise) rescue [1, 2]

This makes multiple assignment with rescue modifier consistent with
single assignment with rescue modifier, applying rescue to the RHS:

  a, b = raise rescue [1, 2] # a, b = (raise rescue [1, 2])

Implements [Feature #8239]
Fixes [Bug #8279]
This commit is contained in:
Jeremy Evans 2019-08-08 20:02:54 -07:00
parent cecae8593a
commit 53b3be5d58
2 changed files with 14 additions and 0 deletions

View file

@ -1387,6 +1387,15 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
/*% %*/
/*% ripper: assign!($1, $3) %*/
}
| mlhs '=' mrhs_arg modifier_rescue stmt
{
/*%%%*/
YYLTYPE loc = code_loc_gen(&@4, &@5);
value_expr($3);
$$ = node_assign(p, $1, NEW_RESCUE($3, NEW_RESBODY(0, remove_begin($5), 0, &loc), 0, &@$), &@$);
/*% %*/
/*% ripper: massign!($1, rescue_mod!($3, $5)) %*/
}
| mlhs '=' mrhs_arg
{
/*%%%*/

View file

@ -92,6 +92,11 @@ class TestAssignment < Test::Unit::TestCase
a,b,*c = *[*[1,2]]; assert_equal([1,2,[]], [a,b,c])
end
def test_assign_rescue
a = raise rescue 2; assert_equal(2, a)
a, b = raise rescue [3,4]; assert_equal([3, 4], [a, b])
end
def test_assign_abbreviated
bug2050 = '[ruby-core:25629]'
a = Hash.new {[]}