Skip to content

Conversation

@pocke
Copy link
Collaborator

@pocke pocke commented Oct 31, 2022

A block pattern raises an error on a method call without the receiver.

For example:

$ cat test.rb
foo

$ querly find a{}.foo
Error: undefined method `type' for nil:NilClass
pattern: a{}.foo
Backtrace:
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:174:in `test_node'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:195:in `test_receiver'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:182:in `test_node'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:159:in `=~'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:42:in `test_pair'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:34:in `block (2 levels) in find'
  /path/to/querly-1.3.0/lib/querly/node_pair.rb:25:in `each_subpair'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:33:in `block in find'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:32:in `each'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:32:in `find'
  /path/to/querly-1.3.0/lib/querly/cli/find.rb:23:in `start'
  /path/to/querly-1.3.0/lib/querly/cli.rb:104:in `find'
  /path/to/thor-1.2.1/lib/thor/command.rb:27:in `run'
  /path/to/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
  /path/to/thor-1.2.1/lib/thor.rb:392:in `dispatch'
  /path/to/thor-1.2.1/lib/thor/base.rb:485:in `start'
  /path/to/querly-1.3.0/exe/querly:8:in `<top (required)>'
  /path/to/bin/querly:25:in `load'
  /path/to/bin/querly:25:in `<main>'

This patch fixes this problem

```console
$ cat test.rb
foo

$ querly find a{}.foo
Error: undefined method `type' for nil:NilClass
pattern: a{}.foo
Backtrace:
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:174:in `test_node'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:195:in `test_receiver'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:182:in `test_node'
  /path/to/querly-1.3.0/lib/querly/pattern/expr.rb:159:in `=~'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:42:in `test_pair'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:34:in `block (2 levels) in find'
  /path/to/querly-1.3.0/lib/querly/node_pair.rb:25:in `each_subpair'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:33:in `block in find'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:32:in `each'
  /path/to/querly-1.3.0/lib/querly/analyzer.rb:32:in `find'
  /path/to/querly-1.3.0/lib/querly/cli/find.rb:23:in `start'
  /path/to/querly-1.3.0/lib/querly/cli.rb:104:in `find'
  /path/to/thor-1.2.1/lib/thor/command.rb:27:in `run'
  /path/to/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
  /path/to/thor-1.2.1/lib/thor.rb:392:in `dispatch'
  /path/to/thor-1.2.1/lib/thor/base.rb:485:in `start'
  /path/to/querly-1.3.0/exe/querly:8:in `<top (required)>'
  /path/to/bin/querly:25:in `load'
  /path/to/bin/querly:25:in `<main>'
```
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

Successfully merging this pull request may close these issues.

1 participant