Fix bad argument collection with optional positionals
This commit is contained in:
parent
258527ef7b
commit
eeca53e4f1
7
src/vm.c
7
src/vm.c
@ -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();
|
||||
}
|
||||
|
9
test/testOptionalAndCollected.krk
Normal file
9
test/testOptionalAndCollected.krk
Normal 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)
|
6
test/testOptionalAndCollected.krk.expect
Normal file
6
test/testOptionalAndCollected.krk.expect
Normal 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}
|
Loading…
Reference in New Issue
Block a user