blueloveTH 4 тижнів тому
батько
коміт
cbbe319520
2 змінених файлів з 14 додано та 0 видалено
  1. 3 0
      src/compiler/compiler.c
  2. 11 0
      tests/160_functions.py

+ 3 - 0
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)

+ 11 - 0
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)