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

Two cops crash when scanning code using super #90

Closed
jonas054 opened this issue Apr 24, 2013 · 1 comment
Closed

Two cops crash when scanning code using super #90

jonas054 opened this issue Apr 24, 2013 · 1 comment

Comments

@jonas054
Copy link
Collaborator

This code:

class Base
  def func
    "Hello"
  end
end

class Derived < Base
  def func
    super.slice(1..2)
  end
end

puts Derived.new.func

gives this stack dump:

/home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/hash_literal.rb:12:in `block in inspect': undefined method `[]' for nil:NilClass (NoMethodError)
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
[...]
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/hash_literal.rb:9:in `inspect'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:74:in `block (2 levels) in run'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `each'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `block in run'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `each'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `run'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/bin/rubocop:13:in `block in <top (required)>'
    from /home/jonas/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/bin/rubocop:12:in `<top (required)>'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `load'
    from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `<main>'

So HashLiteral crashes. The same goes for ArrayLiteral if HashLiteral is disabled. I have a fix for the problem.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 24, 2013

Nice catch.

@bbatsov bbatsov closed this as completed Apr 24, 2013
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