Skip to content

Commit

Permalink
+ ruby30.y: reject endless setter. (#736)
Browse files Browse the repository at this point in the history
This commit tracks upstream commit ruby/ruby@53ba9fb.
  • Loading branch information
iliabylich committed Sep 2, 2020
1 parent 2f226a3 commit cd1bfe0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/parser/messages.rb
Expand Up @@ -74,6 +74,7 @@ module Parser
:undefined_lvar => "no such local variable: `%{name}'",
:duplicate_variable_name => 'duplicate variable name %{name}',
:duplicate_pattern_key => 'duplicate hash pattern key %{name}',
:endless_setter => 'setter method cannot be defined in an endless method definition',

# Parser warnings
:useless_else => 'else without rescue is useless',
Expand Down
6 changes: 6 additions & 0 deletions lib/parser/ruby30.y
Expand Up @@ -866,6 +866,12 @@ rule
}
| defn_head f_paren_args tEQL arg
{
_def_t, name_t = val[0]

if name_t[0].end_with?('=')
diagnostic :error, :endless_setter, nil, name_t
end

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

Expand Down
8 changes: 8 additions & 0 deletions test/test_parser.rb
Expand Up @@ -9975,4 +9975,12 @@ def test_reserved_for_numparam__since_30
SINCE_3_0)
end
end

def test_endless_setter
assert_diagnoses(
[:error, :endless_setter],
%q{def foo=() = 42},
%q{ ^^^^ location},
SINCE_3_0)
end
end

0 comments on commit cd1bfe0

Please sign in to comment.