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

Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass #192

Closed
daBee opened this issue May 11, 2022 · 7 comments
Closed

Comments

@daBee
Copy link

daBee commented May 11, 2022

For no new Ctags, I'm getting an undefined method error:

starscope --force-update zz_before.rb zz_after.rb
Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass

          yield :end, :end, line_no: loc.end.line, type: :func, col: loc.end.column
                                            ^^^^^" while extracting /Users/rich/RF/RFS/Admin/tugsearch.rb
Updating: 322/322 Time: 00:00:00 ||==========================================>||

This implements something new, the Ruby 3.x syntax for method definitions:

def get_lastfile(dirpath) = Dir.glob("#{ dirpath }/*").reject { |i| File.directory?(i) }.sort.last

Commenting that out allows the process to continue to completion over many files. I'm guessing there should be a test for a nil result, or recognition for the new type of Ruby syntax for single line method definitions.

@eapache
Copy link
Owner

eapache commented May 13, 2022

🤔 I wonder if it might not be as simple as requiring a later version of the parser gem so that it can generate a better AST for Ruby 3.x syntax? I'll take a look at this, but checking what version of parser you have might be a place to start.

@daBee
Copy link
Author

daBee commented May 13, 2022

I'm finding other packages/software aren't up to date with version 3.x syntax. Also, the parser gem is up to date: Parser is at 3.1.2.0. In fact, I will post this issue over there.

The EOL error is an indication that Ruby 3.x method structure is perceived as missing something. If this gem is what you say is tripping, then it sounds logical.

@iliabylich
Copy link

whitequark/parser maintainer here. def and defs node for endless methods (i.e. def foo = 42) produce no .end location.

In general I'd suggest to not require parser/current because there can be changes to the Ruby language that require "clients" of whitequark/parser to adapt to these changes. Technically it's not a breaking change, old syntax is still parsed with non-nullable .end location. Instead I'd recommend to require parser/ruby<LATEST> and to do a manual upgrade to support new language constructions on each upgrade of the major Ruby version.

@eapache
Copy link
Owner

eapache commented May 14, 2022

Thank you for the report, and thank you for the advice on using parser. I've pushed a commit to the main branch which pins starscope to parsing Ruby 3.1, and should also handle the new syntax (though I don't have an extensive corpus of Ruby 3.1 code handy so I may still be missing edge cases).

Please feel free to reopen, or to file a separate issue if there are still problems.

@eapache eapache closed this as completed May 14, 2022
@daBee
Copy link
Author

daBee commented Aug 7, 2022

Not sure if this has been addressed yet. I'm still showing issues that might be related to this:

Building: |
Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass

          yield :end, :end, line_no: loc.end.line, type: :func, col: loc.end.column
                                            ^^^^^" while extracting methods.rb
Building: |======
Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass

          yield :end, :end, line_no: loc.end.line, type: :func, col: loc.end.column
                                            ^^^^^" while extracting /Users/user3/AB/Admin/tugsearch.rb
Building: |===============
Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass

          yield :end, :end, line_no: loc.end.line, type: :func, col: loc.end.column
                                            ^^^^^" while extracting /Users/user3/AB/Browsers/current_html_to_bbedit.rb
Building: |=======================================================
Starscope::Lang::Ruby raised "undefined method `line' for nil:NilClass

          yield :end, :end, line_no: loc.end.line, type: :func, col: loc.end.column
                                            ^^^^^" while extracting /Users/user3/AB/crons/forecast_warn.rb
Building: |====================================================================|
No changes detected.

Version 1.6.0 with Ruby 3.1.2p20

@eapache
Copy link
Owner

eapache commented Aug 7, 2022

The fix for this is only in v1.6.1 which I didn't actually release - there was another thing I was waiting on and it never happened and then I just forgot. I'll release it shortly, and you can try the latest main branch in the meantime.

@daBee
Copy link
Author

daBee commented Aug 7, 2022

Ya I'm good. Juts wasn't sure if it was complicated and taking some time.

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

3 participants