Skip to content
Browse files

Some more kwargs error work++

  • Loading branch information...
1 parent f8f16cc commit eb49e0c1823de5c78fb0371c3db0671565e38149 @enebo enebo committed Mar 6, 2014
View
8 core/src/main/java/org/jruby/ir/IRBuilder.java
@@ -1912,14 +1912,20 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode, IRScope s) {
int rest = argsNode.getRestArg();
s.getStaticScope().setArities(required, opt, rest);
+ KeywordRestArgNode keyRest = argsNode.getKeyRest();
// For closures, we don't need the check arity call
if (s instanceof IRMethod) {
// FIXME: Expensive to do this explicitly? But, two advantages:
// (a) on inlining, we'll be able to get rid of these checks in almost every case.
// (b) compiler to bytecode will anyway generate this and this is explicit.
// For now, we are going explicit instruction route. But later, perhaps can make this implicit in the method setup preamble?
- KeywordRestArgNode keyRest = argsNode.getKeyRest();
+
+ addInstr(s, new CheckArityInstr(required, opt, rest, argsNode.hasKwargs(),
+ keyRest == null ? -1 : keyRest.getIndex()));
+ } else if (s instanceof IRClosure && argsNode.hasKwargs()) {
+ // FIXME: This is added to check for kwargs correctness but bypass regular correctness.
+ // Any other arity checking currently happens within Java code somewhere (RubyProc.call?)
addInstr(s, new CheckArityInstr(required, opt, rest, argsNode.hasKwargs(),
keyRest == null ? -1 : keyRest.getIndex()));
}
View
10 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
@@ -437,8 +437,8 @@ public static void checkArity(ThreadContext context, Object[] args, int required
if (keywordArgs != null) argsLength -= 1;
if (argsLength < required || (rest == -1 && argsLength > (required + opt))) {
- //System.out.println("NUMARGS: " + numArgs + ", REQUIRED: " + required + ", OPT: " + opt + "KWARCOU: " + kwArgHashCount + ", AL: " + args.length + ",RKW: " + receivesKeywords );
- //System.out.println("ARGS[0]: " + args[0]);
+// System.out.println("NUMARGS: " + argsLength + ", REQUIRED: " + required + ", OPT: " + opt + ", AL: " + args.length + ",RKW: " + receivesKwargs );
+// System.out.println("ARGS[0]: " + args[0]);
Arity.raiseArgumentError(context.runtime, argsLength, required, required + opt);
}
@@ -460,8 +460,12 @@ public static void checkForExtraUnwantedKeywordArgs(final ThreadContext context,
@Override
public void visit(IRubyObject key, IRubyObject value) {
String keyAsString = key.asJavaString();
+ int slot = scope.isDefined((keyAsString));
- if (scope.isDefined(keyAsString) < 0) throw context.runtime.newArgumentError("unknown keyword: " + keyAsString);
+ // Found name in higher variable scope. Therefore non for this block/method def.
+ if ((slot >> 16) > 0) throw context.runtime.newArgumentError("unknown keyword: " + keyAsString);
+ // Could not find it anywhere.
+ if (((short) (slot & 0xffff)) < 0) throw context.runtime.newArgumentError("unknown keyword: " + keyAsString);
}
});
}

0 comments on commit eb49e0c

Please sign in to comment.
Something went wrong with that request. Please try again.