Skip to content

Commit

Permalink
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.InlineCloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;

public class CheckArityInstr extends Instr implements FixedArityInstr {
@@ -64,8 +65,8 @@ public static CheckArityInstr decode(IRReaderDecoder d) {
return new CheckArityInstr(d.decodeInt(), d.decodeInt(), d.decodeInt(), d.decodeBoolean(), d.decodeInt());
}

public void checkArity(ThreadContext context, Object[] args) {
IRRuntimeHelpers.checkArity(context, args, required, opt, rest, receivesKeywords, restKey);
public void checkArity(ThreadContext context, Object[] args, Block.Type blockType) {
IRRuntimeHelpers.checkArity(context, args, required, opt, rest, receivesKeywords, restKey, blockType);
}

@Override
Original file line number Diff line number Diff line change
@@ -170,7 +170,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, implClass, null);
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, null);
}
break;
case OTHER_OP:
@@ -328,7 +328,7 @@ protected static void processCall(ThreadContext context, Instr instr, Operation

protected static void processBookKeepingOp(ThreadContext context, Instr instr, Operation operation,
String name, IRubyObject[] args, IRubyObject self, Block block,
RubyModule implClass, Stack<Integer> rescuePCs) {
Block.Type blockType, RubyModule implClass, Stack<Integer> rescuePCs) {
switch(operation) {
case LABEL:
break;
@@ -356,7 +356,7 @@ protected static void processBookKeepingOp(ThreadContext context, Instr instr, O
context.callThreadPoll();
break;
case CHECK_ARITY:
((CheckArityInstr)instr).checkArity(context, args);
((CheckArityInstr)instr).checkArity(context, args, blockType);
break;
case LINE_NUM:
context.setLine(((LineNumberInstr)instr).lineNumber);
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, implClass, rescuePCs);
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, rescuePCs);
}
break;
case OTHER_OP:
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -507,16 +507,16 @@ public static Block getBlockFromObject(ThreadContext context, Object value) {
}

public static void checkArity(ThreadContext context, Object[] args, int required, int opt, int rest,
boolean receivesKwargs, int restKey) {
boolean receivesKwargs, int restKey, Block.Type blockType) {
int argsLength = args.length;
RubyHash keywordArgs = (RubyHash) extractKwargsHash(args, required, receivesKwargs);
RubyHash keywordArgs = extractKwargsHash(args, required, receivesKwargs);

if (restKey == -1 && keywordArgs != null) checkForExtraUnwantedKeywordArgs(context, keywordArgs);

// keyword arguments value is not used for arity checking.
if (keywordArgs != null) argsLength -= 1;

if (argsLength < required || (rest == -1 && argsLength > (required + opt))) {
if ((blockType == null || blockType.checkArity) && (argsLength < required || (rest == -1 && argsLength > (required + opt)))) {
// System.out.println("NUMARGS: " + argsLength + ", REQUIRED: " + required + ", OPT: " + opt + ", AL: " + args.length + ",RKW: " + receivesKwargs );
// System.out.println("ARGS[0]: " + args[0]);

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -848,7 +848,8 @@ public void CheckArityInstr(CheckArityInstr checkarityinstr) {
jvmAdapter().ldc(checkarityinstr.rest);
jvmAdapter().ldc(checkarityinstr.receivesKeywords);
jvmAdapter().ldc(checkarityinstr.restKey);
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, Object[].class, int.class, int.class, int.class, boolean.class, int.class));
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, Object[].class, int.class, int.class, int.class, boolean.class, int.class, Block.Type.class));
}
}

5 changes: 2 additions & 3 deletions test/mri/excludes/TestKeywordArguments.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude :test_block_required_keyword, "needs investigation"
exclude :test_implicit_hash_conversion, "needs investigation"
exclude :test_p1, "needs investigation"
exclude :test_p3, "needs investigation"
exclude :test_p6, "needs investigation"
exclude :test_lambda, "JIT-only"
exclude :test_p6, "JIT-only"
exclude :test_required_keyword_with_reserved, "needs investigation"
exclude :test_rest_keyrest, "needs investigation"

0 comments on commit 40a4707

Please sign in to comment.