-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
… method This is a syntax error: ``` def foo=(...) end ``` So it must use `public_send` instead in that case. It's caused by https://github.com/rubocop/rubocop-ast/blob/47e0eead4b84c3d28d7251a548e152f914219773/lib/rubocop/ast/node/mixin/collection_node.rb#L9-L10 By default the `Array` class doesn't contain such methods but when something like spring is in use, code can be evaluated before rubocop. I thought about simply rejecting such methods but supporting it is easy enough
- Loading branch information
Showing
3 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#360](https://github.com/rubocop/rubocop-ast/pull/360): Fix an error when the `Array` core class contains a writer method before `rubocop-ast` loaded. ([@earlopain][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::SimpleForwardable do | ||
let(:delegator) do | ||
Class.new do | ||
attr_reader :target | ||
|
||
def initialize | ||
@target = Struct.new(:foo).new | ||
end | ||
|
||
extend RuboCop::SimpleForwardable | ||
|
||
def_delegators :target, :foo=, :foo | ||
end | ||
end | ||
|
||
it 'correctly delegates to writer methods' do | ||
d = delegator.new | ||
d.foo = 123 | ||
expect(d.foo).to eq(123) | ||
end | ||
end |
5459734
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.
this is still going to fail for both 'foo?' and 'foo!', at minimum. #fyi
5459734
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.
I tested these and it seemed to work in all rubies that support
...
delegation. Do you have a concrete example I can try out?5459734
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.
5459734
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.
No worries, thanks for double-checking! The rules about writer methods are pretty weird.