-
Notifications
You must be signed in to change notification settings - Fork 200
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
- fix a false positive for endless method definition #796
- fix a false positive for endless method definition #796
Conversation
7fa7dd9
to
9dd8521
Compare
lib/parser/ruby30.y
Outdated
@@ -3071,7 +3071,7 @@ require 'parser' | |||
end | |||
|
|||
def endless_method_name(name_t) | |||
if name_t[0].end_with?('=') | |||
if !%w[== === >= <= !=].include?(name_t[0]) && name_t[0].end_with?('=') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]=
should also be in this list (and who knows what else):
> ObjectSpace.each_object(Class).flat_map(&:instance_methods).uniq.select { |mid| mid.to_s.end_with?('=') && !(mid.to_s[-2] =~ /\w/) }
=> [:===, :==, :!=, :<=, :>=, :[]=]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, or is it a setter? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]=
will also result in the error on MRI :-)
% ruby -ve "def []=(index, value) = 42"
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19]
-e:1: setter method cannot be defined in an endless method definition
def []=(index, value) = 42
% ruby -ve "def []=(index, value) = 42"
ruby 3.1.0dev (2021-04-06T07:03:20Z master 31ba817887) [x86_64-darwin19]
-e:1: setter method cannot be defined in an endless method definition
def []=(index, value) = 42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right. It's a setter, so it's an error and it's expected. I updated this PR again.
test/test_parser.rb
Outdated
@@ -10107,6 +10107,73 @@ def test_endless_setter | |||
SINCE_3_0) | |||
end | |||
|
|||
def test_endless_comparison_method | |||
assert_parses( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite it into a loop that iterates over method names please? Also, source maps are redundant here.
9dd8521
to
fc635a8
Compare
Thank you for your review. I've updated this PR. |
Fixes: whitequark#795. This PR fixes false positives that comparison methods recognizes as a setter method.
fc635a8
to
63fd724
Compare
@koic Thanks! |
Thanks too! |
Fixes: #795.
This PR fixes false positives that comparison methods recognizes as a setter method.