Skip to content

Commit 8a91291

Browse files
transclaude
andcommitted
Fix Binding#caller_locations arity (JRuby warn uplevel)
Binding#caller and #caller_locations were defined with arity 0..1, but Kernel#caller/#caller_locations accept (start, length). When warn(uplevel:) dispatches to caller_locations on a Binding receiver — as it does under JRuby's pure-Ruby warn — it passes 2 args and raised ArgumentError. Widen both to accept the optional length, keeping the 0/1-arg behavior unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 03c27ba commit 8a91291

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Changes:
1414
* Restore `Range#overlap?` for Ruby < 3.3. It was dropped in 3.2.0 (since Ruby
1515
3.3 added a native one), which left 3.1/3.2 users without it. It is now
1616
defined only when missing, so it never replaces the built-in on 3.3+.
17+
* Widen `Binding#caller` and `Binding#caller_locations` to accept the optional
18+
`length` argument (matching `Kernel#caller`/`#caller_locations`). The
19+
too-narrow arity raised `ArgumentError` when `warn(uplevel:)` dispatched to
20+
them under JRuby's pure-Ruby `warn`.
1721

1822
* Internal
1923

lib/core/facets/binding/caller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ class Binding
44

55
# Returns the call stack, same format as Kernel#caller()
66
#
7-
def caller( skip=0 )
8-
eval("caller(#{skip})")
7+
# Accepts the same `(start, length)` arguments as Kernel#caller.
8+
#
9+
def caller( start=0, length=nil )
10+
length ? eval("caller(#{start}, #{length})") : eval("caller(#{start})")
911
end
1012

1113
# Returns the call stack, same format as Kernel#caller_locations()
1214
#
13-
def caller_locations( skip=0 )
14-
eval("caller_locations(#{skip})")
15+
# Accepts the same `(start, length)` arguments as Kernel#caller_locations.
16+
#
17+
def caller_locations( start=0, length=nil )
18+
length ? eval("caller_locations(#{start}, #{length})") : eval("caller_locations(#{start})")
1519
end
1620

1721
# Return the line number on which the binding was created.

0 commit comments

Comments
 (0)