Fix bad argument collection with optional positionals

This commit is contained in:
K. Lange 2022-07-11 10:03:00 +09:00
parent 258527ef7b
commit eeca53e4f1
3 changed files with 18 additions and 4 deletions

View File

@ -890,13 +890,12 @@ _finishKwarg:
argCountX = argCount - (!!(closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_COLLECTS_ARGS) + !!(closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_COLLECTS_KWS));
} else if ((size_t)argCount > potentialPositionalArgs && (closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_COLLECTS_ARGS)) {
krk_push(NONE_VAL()); krk_push(NONE_VAL()); krk_pop(); krk_pop();
KrkValue * startOfPositionals = &krk_currentThread.stackTop[-argCount];
KrkValue tmp = krk_list_of(argCount - potentialPositionalArgs,
&startOfPositionals[potentialPositionalArgs], 0);
KrkValue tmp = krk_callNativeOnStack(argCount - potentialPositionalArgs,
&startOfPositionals[potentialPositionalArgs], 0, krk_list_of);
startOfPositionals = &krk_currentThread.stackTop[-argCount];
startOfPositionals[offsetOfExtraArgs] = tmp;
argCount = closure->function->requiredArgs + 1;
argCount = potentialPositionalArgs + 1;
argCountX = argCount - 1;
while (krk_currentThread.stackTop > startOfPositionals + argCount) krk_pop();
}

View File

@ -0,0 +1,9 @@
def foo(a,b=42,*args,**kwargs):
print(a,b,args,kwargs)
foo(1)
foo(1,2)
foo(1,2,3)
foo(1,2,3,4,5,6)
foo(1,2,f=7)
foo(b=2,a=7,k=96)

View File

@ -0,0 +1,6 @@
1 42 [] {}
1 2 [] {}
1 2 [3] {}
1 2 [3, 4, 5, 6] {}
1 2 [] {'f': 7}
7 2 [] {'k': 96}