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/CaseLikeIf: undefined method `literal?' for nil:NilClass #8344

Closed
leoarnold opened this issue Jul 15, 2020 · 1 comment · Fixed by #8345
Closed

Style/CaseLikeIf: undefined method `literal?' for nil:NilClass #8344

leoarnold opened this issue Jul 15, 2020 · 1 comment · Fixed by #8345
Labels

Comments

@leoarnold
Copy link
Contributor

Expected behavior

Run without exception on sample file

module InstanceMethods
  # Returns true if both instances have the same class and identical attributes
  def ==(other)
    if equal?(other)
      true
    elsif other.instance_of?(self.class)
      keys = self.class.attributes.keys
      attributes.values_at(*keys) == other.attributes.values_at(*keys)
    else
      false
    end
  end
end

Actual behavior

$ rubocop -d test.rb 
For /home/user/Code/project: configuration from /home/user/Code/project/.rubocop.yml
configuration from /home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-performance-1.7.0/config/default.yml
configuration from /home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-performance-1.7.0/config/default.yml
Default configuration from /home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-0.88.0/config/default.yml
configuration from /home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-rspec-1.42.0/config/default.yml
configuration from /home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-rspec-1.42.0/config/default.yml
Inspecting 1 file
Scanning /home/user/Code/project/test.rb
An error occurred while Style/CaseLikeIf cop was inspecting /home/user/Code/project/test.rb:4:4.
undefined method `literal?' for nil:NilClass
/home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-0.88.0/lib/rubocop/cop/style/case_like_if.rb:118:in `find_target_in_equality_node'
/home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-0.88.0/lib/rubocop/cop/style/case_like_if.rb:101:in `find_target_in_send_node'
/home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-0.88.0/lib/rubocop/cop/style/case_like_if.rb:91:in `find_target'
/home/user/.rvm/gems/ruby-2.6.6@project/gems/rubocop-0.88.0/lib/rubocop/cop/style/case_like_if.rb:37:in `on_if'
[...]

Steps to reproduce the problem

See above for command and gem versions

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ rubocop -V
0.88.0 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.6.6 x86_64-linux)
@koic koic added the bug label Jul 15, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 15, 2020

Looks like a task for @fatkodima.

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