-
Notifications
You must be signed in to change notification settings - Fork 203
+ ruby31.y: parse anonymous block argument. #833
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
Merged
Merged
Conversation
This file contains hidden or 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 commit tracks upstream commit ruby/ruby@4adb012.
That was the last 3.1 change, feel free to ping me if you need a release. |
Yes, please) |
|
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
Nov 30, 2021
Follow up to whitequark/parser#833. Here is a traditional block argument. ```console % ruby-parse -e 'def foo(&b) = bar(&b)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg :b)) (send nil :bar (block-pass (lvar :b)))) ``` The anonymous block argument introduced in Ruby 3.1, the value of `block-pass` is nil. So `block-pass` will have the possibility of having nil. ```console % ruby-parse -e 'def foo(&) = bar(&)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg nil)) (send nil :bar (block-pass nil))) ``` This PR prevents the following error that occur when anonymous block argument is used: ```console % ruby -rrubocop-ast -e 'include RuboCop::AST::Traversal; walk(RuboCop::AST::ProcessedSource.new("def foo(&) = bar(&)", 3.1).ast)' /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:131:in `on_block_pass': undefined method `type' for nil:NilClass (NoMethodError) from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:154:in `on_def' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:20:in `walk' from -e:1:in `<main>' ```
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
Nov 30, 2021
Follow up to whitequark/parser#833. Here is a traditional block forwarding. ```console % ruby-parse -e 'def foo(&b) = bar(&b)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg :b)) (send nil :bar (block-pass (lvar :b)))) ``` The anonymous block argument introduced in Ruby 3.1, the value of `block-pass` is nil. So `block-pass` will have the possibility of having nil. ```console % ruby-parse -e 'def foo(&) = bar(&)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg nil)) (send nil :bar (block-pass nil))) ``` This PR prevents the following error that occur when anonymous block forwarding is used: ```console % ruby -rrubocop-ast -e 'include RuboCop::AST::Traversal; walk(RuboCop::AST::ProcessedSource.new("def foo(&) = bar(&)", 3.1).ast)' /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:131:in `on_block_pass': undefined method `type' for nil:NilClass (NoMethodError) from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:154:in `on_def' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:20:in `walk' from -e:1:in `<main>' ```
marcandre
pushed a commit
to rubocop/rubocop-ast
that referenced
this pull request
Dec 2, 2021
Follow up to whitequark/parser#833. Here is a traditional block forwarding. ```console % ruby-parse -e 'def foo(&b) = bar(&b)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg :b)) (send nil :bar (block-pass (lvar :b)))) ``` The anonymous block argument introduced in Ruby 3.1, the value of `block-pass` is nil. So `block-pass` will have the possibility of having nil. ```console % ruby-parse -e 'def foo(&) = bar(&)' warning: parser/current is loading parser/ruby31, which recognizes warning: 3.1.0-dev-compliant syntax, but you are running 3.1.0. warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri. (def :foo (args (blockarg nil)) (send nil :bar (block-pass nil))) ``` This PR prevents the following error that occur when anonymous block forwarding is used: ```console % ruby -rrubocop-ast -e 'include RuboCop::AST::Traversal; walk(RuboCop::AST::ProcessedSource.new("def foo(&) = bar(&)", 3.1).ast)' /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:131:in `on_block_pass': undefined method `type' for nil:NilClass (NoMethodError) from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:156:in `on_send' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:154:in `on_def' from /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.13.0/lib/rubocop/ast/traversal.rb:20:in `walk' from -e:1:in `<main>' ```
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
Dec 17, 2021
Follow up to whitequark/parser#833. This PR adds `anonymous_block_argument?` method to `AST::ParameterizedNode` for Ruby 3.1's anonymous block argument syntax. `AST::ParameterizedNode` already has `block_argument?`. So, make it responsible for having `anonymous_block_argument` as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit tracks upstream commit ruby/ruby@4adb012.
Closes #826