Skip to content

Commit d661885

Browse files
committed
Expand Data empty kwargs fix to Struct
This expands the fix from jruby#9215 to Struct and creats a new utility method for checking that keywords were passed AND were non-empty. Fixes jruby#9224.
1 parent 4db0c8a commit d661885

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

core/src/main/java/org/jruby/RubyData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD_EMPTY;
4444
import static org.jruby.runtime.ThreadContext.clearCallInfo;
4545
import static org.jruby.runtime.ThreadContext.hasKeywords;
46+
import static org.jruby.runtime.ThreadContext.hasNonemptyKeywords;
4647
import static org.jruby.runtime.ThreadContext.resetCallInfo;
4748
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
4849
import static org.jruby.util.RubyStringBuilder.str;
@@ -310,7 +311,7 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject self, IRubyOb
310311

311312
RubyHash init;
312313
int callInfo = resetCallInfo(context);
313-
if (hasKeywords(callInfo) && (callInfo & CALL_KEYWORD_EMPTY) == 0) {
314+
if (hasNonemptyKeywords(callInfo)) {
314315
if (!(hashOrElt instanceof RubyHash)) {
315316
throw argumentError(context, 1, 0, 0);
316317
}

core/src/main/java/org/jruby/RubyStruct.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import static org.jruby.runtime.Helpers.invokedynamic;
7272
import static org.jruby.runtime.ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR;
7373
import static org.jruby.runtime.ThreadContext.hasKeywords;
74+
import static org.jruby.runtime.ThreadContext.hasNonemptyKeywords;
7475
import static org.jruby.runtime.Visibility.PRIVATE;
7576
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
7677
import static org.jruby.RubyEnumerator.SizeFn;
@@ -531,7 +532,7 @@ public IRubyObject initialize(ThreadContext context) {
531532

532533
@JRubyMethod(visibility = PRIVATE)
533534
public IRubyObject initialize(ThreadContext context, IRubyObject arg0) {
534-
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
535+
boolean keywords = hasNonemptyKeywords(ThreadContext.resetCallInfo(context));
535536

536537
if (keywords) {
537538
return setupStructValuesFromHash(context, (RubyHash) arg0);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,14 @@ public static boolean hasKeywords(int callInfo) {
15881588
return (callInfo & CALL_KEYWORD) != 0;
15891589
}
15901590

1591+
public static boolean hasNonemptyKeywords(int callInfo) {
1592+
return (callInfo & CALL_KEYWORD) != 0 && !keywordsEmpty(callInfo);
1593+
}
1594+
1595+
public static boolean keywordsEmpty(int callInfo) {
1596+
return (callInfo & CALL_KEYWORD_EMPTY) != 0;
1597+
}
1598+
15911599
@Deprecated(since = "9.3.0.0")
15921600
public IRubyObject setBackRef(IRubyObject match) {
15931601
if (match.isNil()) return clearBackRef();

0 commit comments

Comments
 (0)