Skip to content

Commit 20d8d11

Browse files
committed
[GR-18163] Fix proc's rest arguments
PullRequest: truffleruby/3717
2 parents ceee526 + c7bd304 commit 20d8d11

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Bug fixes:
4242
* Don't trigger the `method_added` event when changing a method's visibility or calling `module_function` (@paracycle, @nirvdrum).
4343
* Fix `rb_time_timespec_new` function to not call `Time.at` method directly (@andrykonchin).
4444
* Fix `StringIO#write` to transcode strings with encodings that don't match the `StringIO`'s `external_encoding`. (#2839, @flavorjones)
45+
* Fix processing of proc rest arguments located at the beginning if there are no actual arguments (#2921, @andrykonchin).
4546

4647
Compatibility:
4748

spec/ruby/language/proc_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@
161161
end
162162
end
163163

164+
describe "taking |*a, b| arguments" do
165+
it "assigns [] to the argument when passed no values" do
166+
proc { |*a, b| [a, b] }.call.should == [[], nil]
167+
end
168+
end
169+
170+
describe "taking |a, *b, c| arguments" do
171+
it "assigns [] to the argument when passed no values" do
172+
proc { |a, *b, c| [a, b, c] }.call.should == [nil, [], nil]
173+
end
174+
end
175+
164176
describe "taking |a, | arguments" do
165177
before :each do
166178
@l = lambda { |a, | a }

src/main/java/org/truffleruby/language/arguments/ReadRestArgumentNode.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,12 @@ public Object execute(VirtualFrame frame) {
7676

7777
final int length = endIndex - startIndex;
7878

79-
if (startIndex == 0) {
80-
return createArray(RubyArguments.getRawArguments(frame, startIndex, length), length);
79+
if (startIndex >= endIndex) {
80+
noArgumentsLeftProfile.enter();
81+
return createEmptyArray();
8182
} else {
82-
if (startIndex >= endIndex) {
83-
noArgumentsLeftProfile.enter();
84-
return createEmptyArray();
85-
} else {
86-
subsetOfArgumentsProfile.enter();
87-
return createArray(RubyArguments.getRawArguments(frame, startIndex, length), length);
88-
}
83+
subsetOfArgumentsProfile.enter();
84+
return createArray(RubyArguments.getRawArguments(frame, startIndex, length), length);
8985
}
9086
}
9187

0 commit comments

Comments
 (0)