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

Handle nil case typechecking @!parse blocks #727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

apiology
Copy link
Contributor

I hit this on some real-world code, reproduced it with a spec and fixed it:

  1) Solargraph::TypeChecker strict level complains on @!parse blocks too
     Failure/Error:
       stringified_comments[rng.start.line] ||= begin
         buff = associated_comments[rng.start.line]
         buff ? stringify_comment_array(buff) : nil

     NoMethodError:
       undefined method `start' for nil:NilClass

             stringified_comments[rng.start.line] ||= begin
                                     ^^^^^^
     # ./lib/solargraph/source.rb:256:in `comments_for'
     # ./lib/solargraph/type_checker.rb:546:in `block in without_ignored'
     # ./lib/solargraph/type_checker.rb:543:in `reject'
     # ./lib/solargraph/type_checker.rb:543:in `without_ignored'
     # ./lib/solargraph/type_checker.rb:43:in `problems'
     # ./spec/type_checker/levels/strict_spec.rb:15:in `block (3 levels) in <top (required)>'

I hit this on some real-world code, reproduced it with a spec and
fixed it:

```
  1) Solargraph::TypeChecker strict level complains on @!parse blocks too
     Failure/Error:
       stringified_comments[rng.start.line] ||= begin
         buff = associated_comments[rng.start.line]
         buff ? stringify_comment_array(buff) : nil

     NoMethodError:
       undefined method `start' for nil:NilClass

             stringified_comments[rng.start.line] ||= begin
                                     ^^^^^^
     # ./lib/solargraph/source.rb:256:in `comments_for'
     # ./lib/solargraph/type_checker.rb:546:in `block in without_ignored'
     # ./lib/solargraph/type_checker.rb:543:in `reject'
     # ./lib/solargraph/type_checker.rb:543:in `without_ignored'
     # ./lib/solargraph/type_checker.rb:43:in `problems'
     # ./spec/type_checker/levels/strict_spec.rb:15:in `block (3 levels) in <top (required)>'
```
@apiology
Copy link
Contributor Author

@castwide : Let me know if you think this is an issue upstream of the type checker and I can hunt for a better place for the fix - wasn't sure if receiving a nil node in this situation was expected.

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