Permalink
Browse files

Argument error on required keyword arguments

  • Loading branch information...
1 parent a343a52 commit d8860e1473c83520f9dc4ff9f6ad491f4e527172 @enebo enebo committed Mar 4, 2014
@@ -2005,6 +2005,8 @@ public void receiveArgs(final ArgsNode argsNode, IRScope s) {
// Required kwargs have no value and check_arity will throw if they are not provided.
if (kasgn.getValueNode().getNodeType() != NodeType.REQUIRED_KEYWORD_ARGUMENT_VALUE) {
build(kasgn, s);
+ } else {
+ addInstr(s, new RaiseRequiredKeywordArgumentError(argName));
}
addInstr(s, new LabelInstr(l));
}
@@ -90,6 +90,7 @@ private void error(Object object) {
public void PushBindingInstr(PushBindingInstr pushbindinginstr) { error(pushbindinginstr); }
public void PushFrameInstr(PushFrameInstr pushframeinstr) { error(pushframeinstr); }
public void RaiseArgumentErrorInstr(RaiseArgumentErrorInstr raiseargumenterrorinstr) { error(raiseargumenterrorinstr); }
+ public void RaiseRequiredKeywordArgumentErrorInstr(RaiseRequiredKeywordArgumentError instr) { error(instr); }
public void ReceiveClosureInstr(ReceiveClosureInstr receiveclosureinstr) { error(receiveclosureinstr); }
public void ReceiveRubyExceptionInstr(ReceiveRubyExceptionInstr receiveexceptioninstr) { error(receiveexceptioninstr); }
public void ReceiveJRubyExceptionInstr(ReceiveJRubyExceptionInstr receiveexceptioninstr) { error(receiveexceptioninstr); }
@@ -136,6 +136,7 @@
GET_BACKREF(0),
RESTORE_ERROR_INFO(OpFlags.f_has_side_effect),
RAISE_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
+ RAISE_REQUIRED_KEYWORD_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
CHECK_ARITY(OpFlags.f_is_book_keeping_op | OpFlags.f_can_raise_exception),
CHECK_ARGS_ARRAY_ARITY(OpFlags.f_can_raise_exception),
RECORD_END_BLOCK(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
@@ -0,0 +1,37 @@
+package org.jruby.ir.instructions;
+
+import org.jruby.ir.IRVisitor;
+import org.jruby.ir.Operation;
+import org.jruby.ir.operands.Operand;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.DynamicScope;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+/**
+ */
+// FIXME: Consider making argument error a single more generic instruction and combining with RaiseArgumentError
+public class RaiseRequiredKeywordArgumentError extends Instr implements FixedArityInstr {
+ private String name;
+
+ public RaiseRequiredKeywordArgumentError(String name) {
+ super(Operation.RAISE_REQUIRED_KEYWORD_ARGUMENT_ERROR);
+
+ this.name = name;
+ }
+
+ @Override
+ public Operand[] getOperands() {
+ return new Operand[0];
+ }
+
+ @Override
+ public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
+ throw context.runtime.newArgumentError("missing keyword: " + name);
+ }
+
+ @Override
+ public void visit(IRVisitor visitor) {
+ visitor.RaiseRequiredKeywordArgumentErrorInstr(this);
+ }
+}
Oops, something went wrong.

0 comments on commit d8860e1

Please sign in to comment.