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

Lint/NumberConversion cop - undefined method send_type? for nil:NilClass #7106

Closed
ThomasOwens opened this issue Jun 4, 2019 · 2 comments · Fixed by #7109
Closed

Lint/NumberConversion cop - undefined method send_type? for nil:NilClass #7106

ThomasOwens opened this issue Jun 4, 2019 · 2 comments · Fixed by #7109
Labels

Comments

@ThomasOwens
Copy link

ThomasOwens commented Jun 4, 2019

Expected behavior

I created a single file in a Rails application that consists of the following:

# frozen_string_literal: true

class TestController < ApplicationController
  def my_method
    @var = params[:field].to_i if params[:field].present?
  end
end

I would expect that this successfully completes without any errors or offenses detected (at least - it doesn't visually appear that there should be offenses).

Actual behavior

The following stack trace is generated:

An error occurred while Lint/NumberConversion cop was inspecting ./app/controllers/test_controller.rb:5:11.
undefined method `send_type?' for nil:NilClass
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/number_conversion.rb:67:in `date_time_object?'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/number_conversion.rb:44:in `block in on_send'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/number_conversion.rb:39:in `to_method'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/number_conversion.rb:43:in `on_send'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:59:in `block (2 levels) in trigger_responding_cops'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:130:in `with_cop_error_handling'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:58:in `block in trigger_responding_cops'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:57:in `each'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:57:in `trigger_responding_cops'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/ast/traversal.rb:61:in `on_ivasgn'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/ast/traversal.rb:137:in `on_if'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/ast/traversal.rb:100:in `on_def'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/ast/traversal.rb:92:in `on_class'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/ast/traversal.rb:13:in `walk'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:46:in `investigate'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/team.rb:116:in `investigate'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/team.rb:104:in `offenses'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:289:in `inspect_file'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:233:in `block in do_inspection_loop'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:265:in `block in iterate_until_no_changes'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:258:in `loop'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:258:in `iterate_until_no_changes'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:229:in `do_inspection_loop'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:150:in `file_offense_cache'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:130:in `file_offenses'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:118:in `process_file'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:95:in `block in each_inspected_file'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:94:in `each'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:94:in `reduce'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:94:in `each_inspected_file'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:81:in `inspect_files'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:47:in `run'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:210:in `execute_runner'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:80:in `execute_runners'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:51:in `run'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/exe/rubocop:13:in `block in <top (required)>'
~/.rbenv/versions/2.4.2/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
./vendor/bundle/ruby/2.4.0/gems/rubocop-0.71.0/exe/rubocop:12:in `<top (required)>'
./vendor/bundle/ruby/2.4.0/bin/rubocop:23:in `load'
./vendor/bundle/ruby/2.4.0/bin/rubocop:23:in `<top (required)>'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `load'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `kernel_load'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:28:in `run'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli.rb:463:in `exec'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli.rb:27:in `dispatch'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/cli.rb:18:in `start'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/exe/bundle:30:in `block in <top (required)>'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
~/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.17.1/exe/bundle:22:in `<top (required)>'
~/.rbenv/versions/2.4.2/bin/bundle:23:in `load'
~/.rbenv/versions/2.4.2/bin/bundle:23:in `<main>'

In addition to the stack trace, Rubocop does report that 1 file was inspected and no offenses were detected.

RuboCop version

0.71.0 (using Parser 2.6.3.0, running on ruby 2.4.2 x86_64-darwin16)
@koic koic added the bug label Jun 4, 2019
koic added a commit to koic/rubocop that referenced this issue Jun 4, 2019
Fixes rubocop#7106.

This PR fixes an error for `Lint/NumberConversion` when `#to_i` called
on a variable on a hash. It was a regression by rubocop#6676.
@koic
Copy link
Member

koic commented Jun 4, 2019

Thanks for the feedback. I opened a PR #7109.

@ThomasOwens
Copy link
Author

Thanks, @koic. I'm just curious when I can expect this to be in a released version that's accessible via RubyGems. I'm looking to upgrade Rubocop at work, and we need to be using released versions. It's not a rush, but I don't know what the release cycle for Rubocop is. Thanks!

bbatsov pushed a commit that referenced this issue Jun 5, 2019
Fixes #7106.

This PR fixes an error for `Lint/NumberConversion` when `#to_i` called
on a variable on a hash. It was a regression by #6676.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants