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

undefined method `begin' for #<Parser::Source::Map::Variable:0x00000001f113b8> when apply auto-correct #2482

Closed
mguthmuller opened this issue Dec 8, 2015 · 2 comments

Comments

@mguthmuller
Copy link

Hi,

I've got this error when i enable auto-correct with the and/or style rule

undefined method `begin' for #<Parser::Source::Map::Variable:0x00000003779ba8>
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/style/and_or.rb:113:in `correctable_send?'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/style/and_or.rb:95:in `correct_send'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/style/and_or.rb:67:in `block (2 levels) in correction'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/style/and_or.rb:65:in `each'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/style/and_or.rb:65:in `block in correction'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/corrector.rb:46:in `call'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/corrector.rb:46:in `block in rewrite'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/corrector.rb:45:in `each'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/corrector.rb:45:in `rewrite'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/team.rb:91:in `autocorrect_one_cop'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/team.rb:66:in `autocorrect'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cop/team.rb:36:in `inspect_file'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:190:in `inspect_file'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:157:in `block in do_inspection_loop'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:151:in `loop'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:151:in `do_inspection_loop'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:93:in `process_file'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:58:in `block in inspect_files'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:56:in `each'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:56:in `inspect_files'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/runner.rb:34:in `run'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/lib/rubocop/cli.rb:26:in `run'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/bin/rubocop:13:in `block in <top (required)>'
/usr/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/var/lib/gems/2.1.0/gems/rubocop-0.35.1/bin/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'

Rubocop version : 0.35.1

To reproduce the issue :

echo 'h={}; p h if !h or h.empty?' | rubocop --stdin --only Style/AndOr --auto-correct -

There is no issue if I change the condition by removing the not (!) : p h if h or h.empty?
There is no issue if I put parentheses around conditions : p h if (!h) or (h.empty?)

@alexdowad
Copy link
Contributor

Thanks for the nice, concise repro!

alexdowad added a commit to alexdowad/rubocop that referenced this issue Dec 10, 2015
@alexdowad
Copy link
Contributor

This was my bug. Thanks for finding it! I just opened a PR with a fix.

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