Skip to content

Commit

Permalink
Fix SEGV when ripper hits backref_error on command_asgn or arg
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed May 11, 2024
1 parent 68b6fe7 commit 7e604a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parse.y
Expand Up @@ -3382,7 +3382,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs
rb_backref_error(p, $1);
/*% %*/
$$ = NEW_ERROR(&@$);
/*% ripper[error]: backref_error(p, RNODE($:1), assign!(var_field(p, get_value($:1)), $:4)) %*/
/*% ripper[error]: backref_error(p, $1, assign!(var_field(p, get_value($:1)), $:4)) %*/
}
;

Expand Down Expand Up @@ -3981,7 +3981,7 @@ arg : lhs '=' lex_ctxt arg_rhs
/*%%%*/
$$ = NEW_ERROR(&@$);
/*% %*/
/*% ripper[error]: backref_error(p, RNODE($:1), opassign!(var_field(p, get_value($:1)), $:2, $:4)) %*/
/*% ripper[error]: backref_error(p, $1, opassign!(var_field(p, get_value($:1)), $:2, $:4)) %*/
}
| arg tDOT2 arg
{
Expand Down
12 changes: 12 additions & 0 deletions test/ripper/test_parser_events.rb
Expand Up @@ -278,6 +278,18 @@ def test_assign_error_backref
parse('$`, _ = 1', :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
assert_equal '[massign([assign_error(var_field($`)),var_field(_)],1)]', result

thru_assign_error = false
result =
parse('$` += 1', :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
assert_equal '[assign_error(opassign(var_field($`),+=,1))]', result

thru_assign_error = false
result =
parse('$` += cmd 1, 2', :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
assert_equal '[assign_error(assign(var_field($`),command(cmd,[1,2])))]', result
end

def test_assign_error_const_qualified
Expand Down

0 comments on commit 7e604a0

Please sign in to comment.