Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ ruby30.y: reject endless setter. #736

Merged
merged 1 commit into from Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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