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

RuboCop crashes when using safe navigation operator #4394

Closed
onk opened this issue May 19, 2017 · 0 comments
Closed

RuboCop crashes when using safe navigation operator #4394

onk opened this issue May 19, 2017 · 0 comments
Labels

Comments

@onk
Copy link
Contributor

onk commented May 19, 2017

Expected behavior

Finish without error.

Actual behavior

Inspecting 1 file
An error occurred while Style/For cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
To see the complete backtrace run rubocop -d.
An error occurred while Style/Lambda cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

2 errors occurred:
An error occurred while Style/For cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
An error occurred while Style/Lambda cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.48.1 (using Parser 2.4.0.0, running on ruby 2.5.0 x86_64-darwin16)

Steps to reproduce the problem

Create a file test.rb with the content below

foo&.bar do |_|
  baz
end

Run rubocop:

$ rubocop test.rb

stacktrace

An error occurred while Style/For cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
undefined method `method?' for "s(:csend,\n  s(:send, nil, :foo), :bar)":RuboCop::AST::Node
/Users/onaka/src/github.com/bbatsov/rubocop/lib/rubocop/cop/style/for.rb:27:in `on_block'

and

An error occurred while Style/Lambda cop was inspecting /Users/onaka/workspaces/tmp/test.rb:1:0.
undefined method `method?' for "s(:csend,\n  s(:send, nil, :foo), :bar)":RuboCop::AST::Node
/Users/onaka/src/github.com/bbatsov/rubocop/lib/rubocop/ast/node/block_node.rb:95:in `lambda?'

It will be fixed by this.
But, I can not write the test code just like the surroundings.:cry:

-send_node.method?(:lambda)
+send_node.send_type? && send_node.method?(:lambda)

RuboCop version

master

@onk onk changed the title RuboCop crashes when using safe navigation operator. RuboCop crashes when using safe navigation operator May 19, 2017
@bbatsov bbatsov added the bug label May 21, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue May 22, 2017
… operator

Some cops, e.g. `Style/For` and `Style/Lambda` would break when
encountering a safe navigation operator.

This change fixes that by granting the powers of the `SendNode`
extension to `csend` nodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants