Skip to content

Commit

Permalink
Add support for beginless ranges in caller and backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
Lillian Zhang committed Jan 6, 2021
1 parent 89ad87f commit 39bc64c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/main/ruby/truffleruby/core/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,17 +726,13 @@ def printf(*args)
end

def caller(start = 1, limit = nil)
args = if start.is_a? Range
if Primitive.nil? start.end
[start.begin + 1]
else
[start.begin + 1, start.size]
end
elsif Primitive.nil? limit
[start + 1]
else
[start + 1, limit]
end
args = if start.is_a? Range
[start] # handled by caller_locations
elsif Primitive.nil? limit
[start + 1]
else
[start + 1, limit]
end
Kernel.caller_locations(*args).map(&:to_s)
end
module_function :caller
Expand Down
6 changes: 5 additions & 1 deletion src/main/ruby/truffleruby/core/truffle/kernel_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def self.normalize_backtrace_args(omit, length)
end
if Range === omit
range = omit
omit = Primitive.rb_to_int(range.begin)
if Primitive.nil? range.begin
omit = 0
else
omit = Primitive.rb_to_int(range.begin)
end
unless Primitive.nil? range.end
end_index = Primitive.rb_to_int(range.end)
if end_index < 0
Expand Down

0 comments on commit 39bc64c

Please sign in to comment.