Skip to content

Commit aae2ad0

Browse files
committed
Adjusted argument counts in error messages
1 parent 96b6d54 commit aae2ad0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private static Object[] createAndCheckArguments(PythonObject callable, Object[]
329329

330330
if (too_many_args) {
331331
// the node acts as a profile
332-
throw handleTooManyArguments(scope_w, callable, signature, co_argcount, co_kwonlyargcount, defaults.length, avail, methodcall, handleTooMany);
332+
throw handleTooManyArguments(scope_w, callable, signature, co_argcount, co_kwonlyargcount, defaults.length, avail, methodcall, handleTooMany, self instanceof PythonModule ? 1 : 0);
333333
}
334334

335335
boolean more_filling = input_argcount < co_argcount + co_kwonlyargcount;
@@ -355,8 +355,8 @@ private static void applyKeywords(Object callable, Signature signature, Object[]
355355
}
356356

357357
private static PException handleTooManyArguments(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall,
358-
HandleTooManyArgumentsNode node) {
359-
return node.execute(scope_w, callable, signature, co_argcount, co_kwonlyargcount, ndefaults, avail, methodcall);
358+
HandleTooManyArgumentsNode node, int adjustCount) {
359+
return node.execute(scope_w, callable, signature, co_argcount, co_kwonlyargcount, ndefaults, avail, methodcall, adjustCount);
360360
}
361361

362362
private static void fillDefaults(Object callable, Signature signature, Object[] scope_w, Object[] defaults, int input_argcount, int co_argcount, FillDefaultsNode node) {
@@ -372,12 +372,13 @@ private static void fillKwDefaults(Object callable, Object[] scope_w, Signature
372372
@GenerateUncached
373373
protected abstract static class HandleTooManyArgumentsNode extends PNodeWithContext {
374374

375-
public abstract PException execute(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall);
375+
public abstract PException execute(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall,
376+
int adjustCount);
376377

377378
@Specialization(guards = {"co_kwonlyargcount == cachedKwOnlyArgCount"})
378379
@ExplodeLoop
379380
PException doCached(Object[] scope_w, Object callable, Signature signature, int co_argcount, @SuppressWarnings("unused") int co_kwonlyargcount, int ndefaults, int avail,
380-
boolean methodcall,
381+
boolean methodcall, int adjustCount,
381382
@Cached PRaiseNode raise,
382383
@Cached("co_kwonlyargcount") int cachedKwOnlyArgCount) {
383384
int kwonly_given = 0;
@@ -386,23 +387,21 @@ PException doCached(Object[] scope_w, Object callable, Signature signature, int
386387
kwonly_given += 1;
387388
}
388389
}
389-
390390
boolean forgotSelf = methodcall && avail + 1 == co_argcount && (signature.getParameterIds().length == 0 || !signature.getParameterIds()[0].equals("self"));
391-
throw raiseTooManyArguments(callable, co_argcount, ndefaults, avail, forgotSelf, kwonly_given, raise);
391+
throw raiseTooManyArguments(callable, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
392392
}
393393

394394
@Specialization(replaces = "doCached")
395-
PException doUncached(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall,
395+
PException doUncached(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall, int adjustCount,
396396
@Cached PRaiseNode raise) {
397397
int kwonly_given = 0;
398398
for (int i = 0; i < co_kwonlyargcount; i++) {
399399
if (PArguments.getArgument(scope_w, co_argcount + i) != null) {
400400
kwonly_given += 1;
401401
}
402402
}
403-
404403
boolean forgotSelf = methodcall && avail + 1 == co_argcount && (signature.getParameterIds().length == 0 || !signature.getParameterIds()[0].equals("self"));
405-
throw raiseTooManyArguments(callable, co_argcount, ndefaults, avail, forgotSelf, kwonly_given, raise);
404+
throw raiseTooManyArguments(callable, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
406405
}
407406

408407
private static PException raiseTooManyArguments(Object callable, int co_argcount, int ndefaults, int avail, boolean forgotSelf, int kwonly_given, PRaiseNode raise) {

0 commit comments

Comments
 (0)