Skip to content

Commit b975d0f

Browse files
committed
keywords logic in cached and uncached ApplyKeywordsNode has to be the same
1 parent 24da149 commit b975d0f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,17 @@ Object[] applyUncached(Object callee, Signature calleeSignature, Object[] argume
521521
@Cached PRaiseNode raise,
522522
@Exclusive @Cached SearchNamedParameterNode searchParamNode,
523523
@Exclusive @Cached SearchNamedParameterNode searchKwNode) {
524-
boolean takesVarKwds = calleeSignature.takesVarKeywordArgs();
525524
String[] parameters = calleeSignature.getParameterIds();
526525
int positionalParamNum = parameters.length;
527526
String[] kwNames = calleeSignature.getKeywordNames();
528-
PKeyword[] unusedKeywords = new PKeyword[keywords.length];
527+
int kwLen = keywords.length;
528+
PKeyword[] unusedKeywords = calleeSignature.takesVarKeywordArgs() ? new PKeyword[kwLen] : null;
529529
// same as above
530530
int k = 0;
531531
int additionalKwds = 0;
532-
int positionalOnlyArgIndex = calleeSignature.getPositionalOnlyArgIndex();
533-
534532
String lastWrongKeyword = null;
535-
for (int i = 0; i < keywords.length; i++) {
533+
int positionalOnlyArgIndex = calleeSignature.getPositionalOnlyArgIndex();
534+
for (int i = 0; i < kwLen; i++) {
536535
PKeyword kwArg = keywords[i];
537536
String name = kwArg.getName();
538537
int kwIdx = searchParamNode.execute(parameters, name);
@@ -545,13 +544,18 @@ Object[] applyUncached(Object callee, Signature calleeSignature, Object[] argume
545544

546545
if (kwIdx != -1) {
547546
if (positionalOnlyArgIndex > -1 && kwIdx < positionalOnlyArgIndex) {
548-
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD, CreateArgumentsNode.getName(callee), name);
549-
}
550-
if (PArguments.getArgument(arguments, kwIdx) != null) {
551-
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
547+
if (unusedKeywords != null) {
548+
unusedKeywords[k++] = kwArg;
549+
} else {
550+
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD, CreateArgumentsNode.getName(callee), name);
551+
}
552+
} else {
553+
if (PArguments.getArgument(arguments, kwIdx) != null) {
554+
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
555+
}
556+
PArguments.setArgument(arguments, kwIdx, kwArg.getValue());
552557
}
553-
PArguments.setArgument(arguments, kwIdx, kwArg.getValue());
554-
} else if (takesVarKwds) {
558+
} else if (unusedKeywords != null) {
555559
unusedKeywords[k++] = kwArg;
556560
} else {
557561
additionalKwds++;

0 commit comments

Comments
 (0)