-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
Error on case statement parsing #1536
Comments
I checked this with Ruby 3.3. & 3.2, and they also have the problem. Refresher on ranges, 'endless' ranges were added in Ruby 2.6, 'beginless' ranges were added in Ruby 2.7. The following patch seems to fix the errors, but I haven't had time to check further, nor write any tests... diff --git a/lib/yard/parser/ruby/ast_node.rb b/lib/yard/parser/ruby/ast_node.rb
index c9deb3ed..ccfa9b6c 100644
--- a/lib/yard/parser/ruby/ast_node.rb
+++ b/lib/yard/parser/ruby/ast_node.rb
@@ -271,7 +271,7 @@ module YARD
# @return [Fixnum] the starting line number of the node
def line
- line_range && line_range.first
+ line_range && (line_range.begin || line_range.end)
end
# @return [String] the first line of source represented by the node.
@@ -345,8 +345,8 @@ module YARD
elsif !children.empty?
f = children.first
l = children.last
- self.line_range = Range.new(f.line_range.first, l.line_range.last)
- self.source_range = Range.new(f.source_range.first, l.source_range.last)
+ self.line_range = Range.new(f.line_range.begin, l.line_range.end)
+ self.source_range = Range.new(f.source_range.begin, l.source_range.end)
elsif @fallback_line || @fallback_source
self.line_range = @fallback_line
self.source_range = @fallback_source
diff --git a/lib/yard/parser/ruby/ruby_parser.rb b/lib/yard/parser/ruby/ruby_parser.rb
index a7ba5fab..b8eaa7c2 100644
--- a/lib/yard/parser/ruby/ruby_parser.rb
+++ b/lib/yard/parser/ruby/ruby_parser.rb
@@ -627,11 +627,13 @@ module YARD
end
# check upwards from line before node; check node's line at the end
- ((node.line - 1).downto(node.line - 2).to_a + [node.line]).each do |line|
- comment = @comments[line]
- if comment && !comment.empty?
- add_comment(line, node)
- break
+ if (n_l = node.line)
+ ((n_l - 1).downto(n_l - 2).to_a + [n_l]).each do |line|
+ comment = @comments[line]
+ if comment && !comment.empty?
+ add_comment(line, node)
+ break
+ end
end
end
|
Steps to reproduce
Actual Output
Expected Output
Parses successfully.
Environment details:
ruby -v
): ruby 3.4.0dev (2024-02-07T11:34:48Z master 9ebaf7a8ef) [arm64-darwin23]yard -v
): yard 0.9.35The text was updated successfully, but these errors were encountered: