Skip to content

Commit

Permalink
+ ruby28.y: support rescue modifier in endless method definition. (#696)
Browse files Browse the repository at this point in the history
This commit tracks upstream commit ruby/ruby@d7d0d01.
  • Loading branch information
iliabylich committed May 22, 2020
1 parent 742db78 commit ea787b5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/parser/ruby28.y
Expand Up @@ -869,6 +869,23 @@ rule
result = @builder.def_endless_method(*val[0],
val[1], val[2], val[3])

@lexer.cmdarg.pop
@lexer.cond.pop
@static_env.unextend
@context.pop
@current_arg_stack.pop
}
| defn_head f_paren_args tEQL arg kRESCUE_MOD arg
{
rescue_body = @builder.rescue_body(val[4],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_method(*val[0],
val[1], val[2], method_body)

@lexer.cmdarg.pop
@lexer.cond.pop
@static_env.unextend
Expand All @@ -880,6 +897,23 @@ rule
result = @builder.def_endless_singleton(*val[0],
val[1], val[2], val[3])

@lexer.cmdarg.pop
@lexer.cond.pop
@static_env.unextend
@context.pop
@current_arg_stack.pop
}
| defs_head f_paren_args tEQL arg kRESCUE_MOD arg
{
rescue_body = @builder.rescue_body(val[4],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_singleton(*val[0],
val[1], val[2], method_body)

@lexer.cmdarg.pop
@lexer.cond.pop
@static_env.unextend
Expand Down
25 changes: 25 additions & 0 deletions test/test_parser.rb
Expand Up @@ -9520,6 +9520,31 @@ def test_endless_method_without_brackets
)
end

def test_endless_method_with_rescue_mod
assert_parses(
s(:def_e, :m,
s(:args),
s(:rescue,
s(:int, 1),
s(:resbody, nil, nil,
s(:int, 2)), nil)),
%q{def m() = 1 rescue 2},
%q{},
SINCE_2_8)

assert_parses(
s(:defs_e,
s(:self), :m,
s(:args),
s(:rescue,
s(:int, 1),
s(:resbody, nil, nil,
s(:int, 2)), nil)),
%q{def self.m() = 1 rescue 2},
%q{},
SINCE_2_8)
end

def test_rasgn
assert_parses(
s(:rasgn,
Expand Down

0 comments on commit ea787b5

Please sign in to comment.