Skip to content

Commit

Permalink
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1923,12 +1923,12 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode) {
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.opt, argName);
Variable temp = createTemporaryVariable();
// You need at least required+j+1 incoming args for this opt arg to get an arg at all
addInstr(new ReceiveOptArgInstr(temp, signature.required(), signature.pre(), j));
addInstr(BNEInstr.create(l, temp, UndefinedValue.UNDEFINED)); // if 'av' is not undefined, go to default
addInstr(new ReceiveOptArgInstr(av, signature.required(), signature.pre(), j));
addInstr(BNEInstr.create(l, av, UndefinedValue.UNDEFINED)); // if 'av' is not undefined, go to default
addInstr(new CopyInstr(av, buildNil())); // wipe out undefined value with nil
Operand defaultResult = build(n.getValue());
addInstr(new CopyInstr(temp, defaultResult));
addInstr(new CopyInstr(av, defaultResult));
addInstr(new LabelInstr(l));
addInstr(new CopyInstr(av, temp));
}
}

@@ -2024,6 +2024,7 @@ public void receiveArgs(final ArgsNode argsNode) {

// Required kwargs have no value and check_arity will throw if they are not provided.
if (!isRequiredKeywordArgumentValue(kasgn)) {
addInstr(new CopyInstr(av, buildNil())); // wipe out undefined value with nil
build(kasgn);
} else {
addInstr(new RaiseRequiredKeywordArgumentError(argName));
24 changes: 24 additions & 0 deletions spec/compiler/general_spec.rb
Original file line number Diff line number Diff line change
@@ -1080,6 +1080,30 @@ def a; __callee__; end
run('def foo; yield; end; foo {|a = a, b = b, c = c|; [a.inspect, b.inspect, c.inspect]}') do |x|
expect(x).to eq(["nil", "nil", "nil"])
end

run('def foo(a: a, b: b, c: c); [a.inspect, b.inspect, c.inspect]; end; foo') do |x|
expect(x).to eq(["nil", "nil", "nil"])
end
run('def foo; yield; end; foo {|a: a, b: b, c: c|; [a.inspect, b.inspect, c.inspect]}') do |x|
expect(x).to eq(["nil", "nil", "nil"])
end
ensure
$VERBOSE = verbose
end
end

it "combines optional args and zsuper properly" do
begin
verbose = $VERBOSE
$VERBOSE = nil

run('class OptZSuperA; def foo(a, b); [a, b]; end; end; class OptZSuperB < OptZSuperA; def foo(a = "", b = nil); super; end; end; OptZSuperB.new.foo') do |x|
expect(x).to eq(["", nil])
end

run('class OptZSuperA; def foo(a:, b:); [a, b]; end; end; class OptZSuperB < OptZSuperA; def foo(a: "", b: nil); super; end; end; OptZSuperB.new.foo') do |x|
expect(x).to eq(["", nil])
end
ensure
$VERBOSE = verbose
end

0 comments on commit 2991a3b

Please sign in to comment.