Skip to content

Commit ee491bf

Browse files
authored
Merge pull request jruby#9192 from enebo/topic/kwarg_fix
Stab at Fixing jruby#8976
2 parents 27ff6be + 3707dcc commit ee491bf

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,13 @@ private static IRubyObject receiveSpecificArityHashKeywords(ThreadContext contex
717717
int callInfo = ThreadContext.resetCallInfo(context);
718718
boolean isKwarg = (callInfo & CALL_KEYWORD) != 0;
719719

720-
return receiverSpecificArityKwargsCommon(context, last, isKwarg);
720+
if ((callInfo & CALL_SPLATS) != 0 && last.isRuby2KeywordHash()) {
721+
return last.dupFast(context);
722+
}
723+
724+
return isKwarg ?
725+
last.dupFast(context) :
726+
last;
721727
}
722728

723729
private static IRubyObject receiveSpecificArityRuby2HashKeywords(ThreadContext context, RubyHash last) {
@@ -735,13 +741,7 @@ private static IRubyObject receiveSpecificArityRuby2HashKeywords(ThreadContext c
735741
return hash;
736742
}
737743

738-
return receiverSpecificArityKwargsCommon(context, last, false);
739-
}
740-
741-
private static IRubyObject receiverSpecificArityKwargsCommon(ThreadContext context, RubyHash last, boolean isKwarg) {
742-
return isKwarg || last.isRuby2KeywordHash() ?
743-
last.dupFast(context) :
744-
last;
744+
return last;
745745
}
746746

747747
/**

spec/ruby/language/keyword_arguments_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ def m(*a)
8686
m(*[], 42, **{}).should == [42]
8787
end
8888

89+
context "marked as ruby2_keywords_hash" do
90+
it "is not copied when passed as a positional argument" do
91+
h = Hash.ruby2_keywords_hash(a:1)
92+
93+
def bar(a)
94+
a
95+
end
96+
97+
h2 = bar(h)
98+
h2.should equal(h)
99+
Hash.ruby2_keywords_hash?(h).should == true
100+
end
101+
end
102+
89103
context "**" do
90104
it "copies a non-empty Hash for a method taking (*args)" do
91105
def m(*args)

0 commit comments

Comments
 (0)