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

Style/NonNilCheck crashes #3637

Closed
madwort opened this issue Oct 17, 2016 · 5 comments
Closed

Style/NonNilCheck crashes #3637

madwort opened this issue Oct 17, 2016 · 5 comments

Comments

@madwort
Copy link
Contributor

madwort commented Oct 17, 2016

Style/NonNilCheck crashes when run against one of our source files.


Expected behavior

Rubocop to test the source code.

Actual behavior

Crash as follows:

$ bundle exec rubocop SOURCE_DIR/FILE.rb -d
For SOURCE_DIR: configuration from SOURCE_DIR/.rubocop.yml
Inheriting configuration from SOURCE_DIR/.rubocop_todo.yml
Default configuration from SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/config/default.yml
Inheriting configuration from SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/config/enabled.yml
Inheriting configuration from SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/config/disabled.yml
configuration from SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-rspec-1.7.0/config/default.yml
configuration from SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-rspec-1.7.0/config/default.yml
Inspecting 1 file
Scanning SOURCE_DIR/FILE.rb
An error occurred while Style/NonNilCheck cop was inspecting SOURCE_DIR/FILE.rb.
undefined method `keyword' for #<Parser::Source::Map::Ternary:0x007ff37e4006b8>
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/style/non_nil_check.rb:58:in `unless_and_nil_check?'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/style/non_nil_check.rb:39:in `on_send'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:41:in `block (2 levels) in on_send'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:96:in `with_cop_error_handling'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:40:in `block in on_send'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:39:in `each'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:39:in `on_send'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:128:in `on_if'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_if'
(eval):3:in `on_lvasgn'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_lvasgn'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:154:in `on_block'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_block'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:154:in `on_block'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:95:in `on_def'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_def'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:88:in `on_class'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_class'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:141:in `on_while'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_module'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:141:in `on_while'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_module'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:141:in `on_while'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_module'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/ast_node/traversal.rb:12:in `walk'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/commissioner.rb:58:in `investigate'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/team.rb:120:in `investigate'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/team.rb:108:in `offenses'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cop/team.rb:51:in `inspect_file'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:243:in `inspect_file'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:190:in `block in do_inspection_loop'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:222:in `block in iterate_until_no_changes'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:215:in `loop'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:215:in `iterate_until_no_changes'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:186:in `do_inspection_loop'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:101:in `block in file_offenses'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:111:in `file_offense_cache'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:99:in `file_offenses'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:90:in `process_file'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:65:in `each'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:65:in `reduce'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:65:in `each_inspected_file'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:57:in `inspect_files'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/runner.rb:36:in `run'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cli.rb:71:in `execute_runner'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/lib/rubocop/cli.rb:27:in `run'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/bin/rubocop:13:in `block in <top (required)>'
/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/gems/rubocop-0.44.1/bin/rubocop:12:in `<top (required)>'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/bin/rubocop:23:in `load'
SOURCE_DIR/vendor/bundle/ruby/2.2.0/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/NonNilCheck cop was inspecting SOURCE_DIR/FILE.rb.
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.44.1 (using Parser 2.3.1.4, running on ruby 2.2.2 x86_64-linux)
Finished in 0.7579406052827835 seconds

Steps to reproduce the problem

This line causes the cop to crash:

my_var.nil? ? 1 : 0

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.44.1 (using Parser 2.3.1.4, running on ruby 2.2.2 x86_64-linux)
@madwort
Copy link
Contributor Author

madwort commented Oct 17, 2016

crash also present in rubocop 0.44.0 but not in 0.43.0.

@mikegee
Copy link
Contributor

mikegee commented Oct 17, 2016

I can't duplicate with master, 0.44.1, or 0.44.0. Perhaps it depends on non-standard configuration? Please post your config.

@madwort
Copy link
Contributor Author

madwort commented Oct 17, 2016

Sorry about that, good point, my config does have this set:

Style/NonNilCheck:
  IncludeSemanticChanges: true

@madwort
Copy link
Contributor Author

madwort commented Oct 17, 2016

(whole contents of .rubocop.yml as follows)

require:
  - rubocop-rspec
  - rubocop-thread_safety

Rails:
  Enabled: true

AllCops:
  Exclude:
    - 'vendor/**/*'
    - 'db/schema.rb'
    - 'db/migrate/*'
  TargetRubyVersion: 2.2

Style/NonNilCheck:
  IncludeSemanticChanges: true

Style/WordArray:
  WordRegex: !ruby/regexp '/\A[\-\:\p{Word}\n\t]+\z/'

inherit_from: .rubocop_todo.yml

@mikegee
Copy link
Contributor

mikegee commented Oct 17, 2016

I duplicated the issue on master with IncludeSemanticChanges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants