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 `include?' for nil:NilClass" on pattern matching #10773

Closed
RDeckard opened this issue Jun 29, 2022 · 2 comments · Fixed by #10888
Closed

"undefined method `include?' for nil:NilClass" on pattern matching #10773

RDeckard opened this issue Jun 29, 2022 · 2 comments · Fixed by #10888
Labels
parser This issue is related to the parser gem

Comments

@RDeckard
Copy link
Contributor

RDeckard commented Jun 29, 2022

I have tried to simplify the problem as much as possible and give all the contextual elements, but do not hesitate to ask me for any useful missing information.

Expected behavior

change this:

existing_attributes => company:, document:, source:

to this:

existing_attributes => company:, document: Invoice, source:

shouldn't make Rubocop to crash.

Actual behavior

This syntax

existing_attributes => company:, document: Invoice, source:

makes Rubocop crash.

Steps to reproduce the problem

1. Create a testfile.rb with just this line

existing_attributes => company:, document:, source:

2. Make sure that Rubocop works

$ rubocop testfile.rb
Inspecting 1 file
C

Offenses:

testfile.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
existing_attributes => company:, document:, source:
^

1 file inspected, 1 offense detected, 1 offense autocorrectable

3. change testfile.rb to this

existing_attributes => company:, document: Invoice, source:

4. Make the issue happen

$ rubocop testfile.rb
undefined method `include?' for nil:NilClass
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/variables_stack.rb:32:in `declared?'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/builders/default.rb:1830:in `check_duplicate_pattern_key'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/builders/default.rb:1640:in `match_pair'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/ruby31.rb:7109:in `_reduce_518'
(eval):3:in `_racc_do_parse_c'
(eval):3:in `do_parse'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/base.rb:190:in `parse'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parser-3.1.2.0/lib/parser/base.rb:238:in `tokenize'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.18.0/lib/rubocop/ast/processed_source.rb:215:in `tokenize'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.18.0/lib/rubocop/ast/processed_source.rb:210:in `parse'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.18.0/lib/rubocop/ast/processed_source.rb:38:in `initialize'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.18.0/lib/rubocop/ast/processed_source.rb:20:in `new'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.18.0/lib/rubocop/ast/processed_source.rb:20:in `from_file'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:424:in `get_processed_source'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:237:in `do_inspection_loop'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:129:in `file_offenses'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:67:in `block in warm_cache'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:587:in `call_with_index'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:557:in `process_incoming_jobs'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:537:in `block in worker'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:528:in `fork'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:528:in `worker'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:519:in `block in create_workers'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `each'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `each_with_index'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `create_workers'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:457:in `work_in_processes'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:294:in `map'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parallel-1.22.1/lib/parallel.rb:238:in `each'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:67:in `warm_cache'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/runner.rb:46:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/command.rb:11:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli/environment.rb:18:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli.rb:71:in `run_command'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli.rb:78:in `execute_runners'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/lib/rubocop/cli.rb:47:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/exe/rubocop:19:in `block in <top (required)>'
~/.asdf/installs/ruby/3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.31.0/exe/rubocop:19:in `<top (required)>'
~/.asdf/installs/ruby/3.1.2/bin/rubocop:25:in `load'
~/.asdf/installs/ruby/3.1.2/bin/rubocop:25:in `<top (required)>'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli/exec.rb:58:in `load'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli/exec.rb:23:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli.rb:483:in `exec'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli.rb:31:in `dispatch'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/cli.rb:25:in `start'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/exe/bundle:48:in `block in <top (required)>'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
~/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.13/exe/bundle:36:in `<top (required)>'
~/.asdf/installs/ruby/3.1.2/bin/bundle:25:in `load'
~/.asdf/installs/ruby/3.1.2/bin/bundle:25:in `<main>'

Context

RuboCop version

$ rubocop -V
1.31.0 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.1.2 arm64-darwin21)

Config file

# .rubocop.yml
AllCops:
  TargetRubyVersion: 3.1.2
  NewCops: enable
@RDeckard RDeckard changed the title "undefined method for nil:NilClass" on a legit (and working) pattern matching syntax "undefined method for nil:NilClass" on pattern matching Jun 29, 2022
@RDeckard RDeckard changed the title "undefined method for nil:NilClass" on pattern matching "undefined method `include?' for nil:NilClass" on pattern matching Jun 29, 2022
@koic koic added the parser This issue is related to the parser gem label Jun 29, 2022
@dvandersluis
Copy link
Member

@koic looks like the parser bug was fixed but there isn't a new version released yet?

@koic
Copy link
Member

koic commented Aug 5, 2022

Yep. Let's wait for the new release of the Parser gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser This issue is related to the parser gem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants