diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 2702f82c..e44057c7 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -2301,6 +2301,9 @@ static Error* _compile_f_args(Compiler* self, FuncDecl* decl, bool is_lambda) { int state = 0; // 0 for args, 1 for *args, 2 for k=v, 3 for **kwargs Error* err; do { + // allow trailing comma + if(!is_lambda && curr()->type == TK_RPAREN) break; + if(state >= 3) return SyntaxError(self, "**kwargs should be the last argument"); if(match(TK_MUL)) { if(state < 1) diff --git a/tests/160_functions.py b/tests/160_functions.py index d9f353a5..cbb193e6 100644 --- a/tests/160_functions.py +++ b/tests/160_functions.py @@ -156,6 +156,17 @@ def f(a, assert f(1, 2) == 3 + +# https://github.com/pocketpy/pocketpy/issues/458 +def f( + x: int, + y: int, +): + return x + y + +assert f(1, 2) == 3 + + # try: # f(a=1) # exit(1)