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

nil-reference exception in AlignHash #496

Closed
jfredett opened this issue Sep 19, 2013 · 8 comments · Fixed by #499
Closed

nil-reference exception in AlignHash #496

jfredett opened this issue Sep 19, 2013 · 8 comments · Fixed by #499
Assignees
Labels

Comments

@jfredett
Copy link

I received the following exception on the following code:

Code:

# encoding: utf-8
module Dugout
  module Math
    module Parser
      class Model
        include Katuv::Node
        multiple PrimitiveOp
        multiple DerivedOp
      end
    end

    module Model
      def self.model(name = nil, opts = {}, &block)
        Parser::Model.new(name, opts.merge(parent: nil), &block)
      end
    end
  end
end

The output of rubocop -d was


For /Users/jfredett/code/mine/dugout: configuration from /Users/jfredett/code/mine/dugout/.rubocop.yml
Default configuration from /Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/config/default.yml
Inheriting configuration from /Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/config/enabled.yml
Inheriting configuration from /Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/config/disabled.yml
Inspecting 32 files
Scanning /Users/jfredett/code/mine/dugout/lib/dugout.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/spec_helper.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/shared/op_compiler_examples.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/unit/math/model/definition_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/unit/math/model/reifier_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/unit/math/parser/*_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/integration/math/model/expression_evaluator_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/integration/math/model/expression_language_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/spec/integration/math/model/op_compiler_spec.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/version.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/definition.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/op_compiler.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/reifier.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/attribute.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/display_function.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/implementation.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/model.rb
An error occurred while AlignHash cop was inspecting /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/model.rb.
undefined method `loc' on nil:NilClass.
kernel/delta/kernel.rb:81:in `loc (method_missing)'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cop/style/align_hash.rb:125:in `value_delta'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cop/style/align_hash.rb:22:in `on_hash'
(eval):5:in `on_hash'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cop/commissioner.rb:88:in `with_cop_error_handling'
(eval):4:in `on_hash'
kernel/bootstrap/array.rb:68:in `each'
(eval):2:in `on_hash'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:144:in `on_send'
(eval):9:in `on_send'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:144:in `on_send'
(eval):9:in `on_send'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:132:in `on_defs'
(eval):9:in `on_defs'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:9:in `on_module (process_regular_node)'
(eval):9:in `on_module'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:9:in `on_begin (process_regular_node)'
(eval):9:in `on_begin'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:9:in `on_module (process_regular_node)'
(eval):9:in `on_module'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:255:in `process_all'
kernel/bootstrap/array19.rb:18:in `map'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:254:in `process_all'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/parser-2.0.0.pre8/lib/parser/ast/processor.rb:9:in `on_module (process_regular_node)'
(eval):9:in `on_module'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/ast-1.1.0/lib/ast/processor.rb:239:in `process'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cop/commissioner.rb:56:in `investigate'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cop/team.rb:45:in `inspect_file'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cli.rb:87:in `inspect_file'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cli.rb:48:in `run'
kernel/bootstrap/array.rb:68:in `each'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/lib/rubocop/cli.rb:42:in `run'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/bin/rubocop:14:in `__script__'
/Users/jfredett/.rvm/rubies/rbx-head/lib/benchmark.rb:304:in `measure'
/Users/jfredett/.rvm/rubies/rbx-head/lib/benchmark.rb:318:in `realtime'
/Users/jfredett/.rvm/gems/rbx-head@dugout/gems/rubocop-0.13.0/bin/rubocop:13:in `__script__'
kernel/common/kernel.rb:579:in `load'
/Users/jfredett/.rvm/gems/rbx-head@dugout/bin/rubocop:23:in `__script__'
kernel/common/block_environment.rb:55:in `call_on_instance'
kernel/common/eval.rb:74:in `eval'
/Users/jfredett/.rvm/gems/rbx-head@dugout/bin/ruby_noexec_wrapper:14:in `__script__'
kernel/delta/codeloader.rb:68:in `load_script'
kernel/delta/codeloader.rb:119:in `load_script'
kernel/loader.rb:645:in `script'
kernel/loader.rb:844:in `main'
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/op.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/operator.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/addition.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/exponential.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/literal.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/log.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/multiplication.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/power.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/sqrt.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/subtraction.rb
.Scanning /Users/jfredett/code/mine/dugout/lib/dugout/math/model/ast/variable.rb
.

32 files inspected, no offences detected

1 error occurred:
An error occurred while AlignHash cop was inspecting /Users/jfredett/code/mine/dugout/lib/dugout/math/parser/model.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.13.0 (using Parser 2.0.0.pre8, running on rbx 1.9.3 x86_64-apple-darwin12.3.0)
Finished in 2.597456932067871 seconds

I also tried (and received the same failure) on 1.9.3 and 2.0.0, latest patches -- this failure is on Rubinius. The trace requested that I post it here, I feel like this is something someone probably has run into before, but I didn't see any issues after a bit of searching that were similar.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 19, 2013

This particular cop is new, so you might very well be the first person who has encountered this problem. @jonas054 would you take a look at it?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 19, 2013

Btw, it's likely something Rubinius specific, since I cannot reproduce the bug with MRI 1.9, MRI 2.0 and JRuby 1.7.4.

@jonas054
Copy link
Collaborator

OK, I'll see what I can do.

@ghost ghost assigned jonas054 Sep 19, 2013
@jfredett
Copy link
Author

I was able to reproduce it on both 1.9 and 2.0 MRI, I'll add dumps in a gist (since they're big), and link it shortly (my internet is spotty at the moment). You should also be able to reproduce it by running rubocop -d on my project jfredett/dugout, as of SHA 13ccbee (the current master).

@jfredett
Copy link
Author

@jonas054
Copy link
Collaborator

Thanks @jfredett for the detailed description of the error!

@jfredett
Copy link
Author

No problem, I poked around the cop-code a bit, but haven't had opportunity to try to fix it. My guess is that it's because the particular line is of the form:

foo.bar(key: nil).other_thing

and in particular, the bar(key: nil) is confusing the cop.

@jonas054
Copy link
Collaborator

Yes, you're in the right place. I've found the problem and will make a pull request shortly.

jonas054 added a commit to jonas054/rubocop that referenced this issue Sep 19, 2013
Single key/value pair when configuration is `table` for '=>' and `separator` for `:`.

Fixes rubocop#496.
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.

3 participants