Skip to content

Commit 574c519

Browse files
Fix block argument destructuring with optional parameters
1 parent e8fe40d commit 574c519

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

core/src/main/java/org/jruby/runtime/IRBlockBody.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public IRubyObject doYield(ThreadContext context, Block block, IRubyObject value
161161
IRubyObject[] args;
162162
if (value == null) { // no args case from BlockBody.yieldSpecific
163163
args = IRubyObject.NULL_ARRAY;
164-
} else if (!signature.isSpreadable()) {
164+
} else if (!signature.isSpreadable() || (signature.opt() + signature.required() == 1 && !signature.hasRest())) {
165165
args = new IRubyObject[] { value };
166166
} else {
167167
args = toAry(context, value);

spec/ruby/language/yield_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
it "passes a single, multi-value Array" do
4949
@y.s([1, 2, 3]) { |*a| a }.should == [[1, 2, 3]]
5050
end
51+
52+
describe "with optional argument" do
53+
it "does not destructure a single array argument" do
54+
@y.s([1, 2, 3]) { |a = 99| a }.should == [1, 2, 3]
55+
end
56+
end
5157
end
5258

5359
describe "yielding to a lambda" do

0 commit comments

Comments
 (0)