Skip to content

Commit

Permalink
Revert "Revert "Fixed arity issue with RubyMethod""
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Feb 12, 2015
1 parent 634af39 commit bd057e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions core/src/main/java/org/jruby/ast/ArgsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,27 @@ public List<Node> childNodes() {

return Node.createList(pre, optArgs, restArgNode, blockArgNode);
}

public int getRequiredKeywordCount() {
if (hasRequiredKeywordArg()) return 1;
return 0;
}

private boolean hasRequiredKeywordArg() {
if (getKeywords() == null) return false;

for (Node keyWordNode :getKeywords().childNodes()) {
for (Node asgnNode : keyWordNode.childNodes()) {
if (isRequiredKeywordArgumentValueNode(asgnNode)) {
return true;
}
}
}
return false;
}

private boolean isRequiredKeywordArgumentValueNode(Node asgnNode) {
return asgnNode.childNodes().get(0) instanceof RequiredKeywordArgumentValueNode;
}

}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ast/MethodDefNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public MethodDefNode(ISourcePosition position, ArgumentNode nameNode, ArgsNode a
this.bodyNode = bodyNode;

// store argument count information into scope
scope.setArities(argsNode.getRequiredArgsCount(), argsNode.getOptionalArgsCount(), argsNode.getRestArg());
scope.setArities(argsNode.getRequiredArgsCount() + argsNode.getRequiredKeywordCount(), argsNode.getOptionalArgsCount(), argsNode.getRestArg());
}


/**
* Gets the argsNode.
* @return Returns a Node
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ public void receiveRequiredArg(Node node, int argIndex, boolean post, int numPre
protected void receiveNonBlockArgs(final ArgsNode argsNode) {
final int numPreReqd = argsNode.getPreCount();
final int numPostReqd = argsNode.getPostCount();
final int required = argsNode.getRequiredArgsCount(); // numPreReqd + numPostReqd
final int required = argsNode.getRequiredArgsCount() + argsNode.getRequiredKeywordCount(); // numPreReqd + numPostReqd
int opt = argsNode.getOptionalArgsCount();
int rest = argsNode.getRestArg();

Expand Down

0 comments on commit bd057e9

Please sign in to comment.