Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/anno/MethodDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public MethodDescriptor(T methodObject) {
* @return arity value of specific required arity which can be used as an unboxed call or -1 for all other cases.
*/
public int calculateSpecificCallArity() {
if (optional == 0 && !rest) {
if (optional == 0 && !rest && !hasVarArgs) {
if (required == 0) {
if (actualRequired <= MAX_REQUIRED_UNBOXED_ARITY) return actualRequired;
} else if (required >= 0 && required <= MAX_REQUIRED_UNBOXED_ARITY) {
Expand Down
25 changes: 25 additions & 0 deletions core/src/test/java/org/jruby/test/TestMethodFactories.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
public class TestMethodFactories extends Base {
public void testInvocationMethodFactory() {
var mod = defineModule(context, "Wombat" + hashCode()).defineMethods(context, MyBoundClass.class);
confirmMethods(mod);
confirmCheckArity(mod);
}

Expand All @@ -57,6 +58,13 @@ private void confirmMethods(RubyModule mod) {
IRubyObject nil = context.nil;
assertTrue("four-arg method should be callable",
mod.searchMethod("four_arg_method").call(context, mod, mod.getMetaClass(), "four_arg_method", new IRubyObject[] {nil, nil, nil, nil}).isTrue());
// methods with required <= 3 and IRubyObject[] args (missing rest=true) should bind and be callable
assertTrue("one-arg method should be callable",
mod.searchMethod("one_arg_method").call(context, mod, mod.getMetaClass(), "one_arg_method", new IRubyObject[] {nil}).isTrue());
assertTrue("two-arg method should be callable",
mod.searchMethod("two_arg_method").call(context, mod, mod.getMetaClass(), "two_arg_method", new IRubyObject[] {nil, nil}).isTrue());
assertTrue("three-arg method should be callable",
mod.searchMethod("three_arg_method").call(context, mod, mod.getMetaClass(), "three_arg_method", new IRubyObject[] {nil, nil, nil}).isTrue());
}

// jruby/jruby#7851: Restore automatic arity checking with an opt-out
Expand Down Expand Up @@ -91,6 +99,23 @@ public static IRubyObject four_arg_method(ThreadContext context, IRubyObject sel
return context.tru;
}

// methods with required <= 3 and IRubyObject[] args (missing rest=true) should bind correctly
// instead of crashing with ArrayIndexOutOfBoundsException in loadArguments
@JRubyMethod(required = 1)
public static IRubyObject one_arg_method(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return context.tru;
}

@JRubyMethod(required = 2)
public static IRubyObject two_arg_method(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return context.tru;
}

@JRubyMethod(required = 3)
public static IRubyObject three_arg_method(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return context.tru;
}

// jruby/jruby#7851: Restore automatic arity checking with an opt-out
@JRubyMethod(required = 1, optional = 1, checkArity = true)
public static IRubyObject optWithCheckArityTrue(ThreadContext context, IRubyObject self, IRubyObject[] args) {
Expand Down
Loading