Skip to content

Commit

Permalink
Prohibit setter method names in endless method definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Aug 31, 2020
1 parent 86737c5 commit 53ba9fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions parse.y
Expand Up @@ -2474,6 +2474,9 @@ arg : lhs '=' arg_rhs
}
| defn_head f_paren_args '=' arg
{
if (is_attrset_id($<node>1->nd_mid)) {
yyerror1(&@1, "setter method cannot be defined in an endless method definition");
}
token_info_drop(p, "def", @1.beg_pos);
restore_defun(p, $<node>1->nd_defn);
/*%%%*/
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_syntax.rb
Expand Up @@ -1429,6 +1429,7 @@ def test_methoddef_endless
end
assert_equal("class ok", k.rescued("ok"))
assert_equal("instance ok", k.new.rescued("ok"))
assert_syntax_error('def foo=() = 42', /setter method cannot be defined in an endless method definition/)
end

def test_methoddef_in_cond
Expand Down

0 comments on commit 53ba9fb

Please sign in to comment.