From 4816ef042808cb6f62eb84d5fd940977ae1739b1 Mon Sep 17 00:00:00 2001 From: "Mateo \"Kuruk\" Miccino" Date: Mon, 9 Feb 2026 10:55:14 -0300 Subject: [PATCH] Fix formatter crash on bare return in lambda The return_stmt handler unconditionally accessed s.children[0], but a bare `return` (without expression) has zero children. This caused an IndexError when formatting lambdas like `func(): return`. The grammar correctly defines return_stmt with an optional expression (`return_stmt: "return" [expr]`), so the formatter now checks for empty children before accessing the list. --- gdtoolkit/formatter/function_statement_to_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdtoolkit/formatter/function_statement_to_str.py b/gdtoolkit/formatter/function_statement_to_str.py index b9cec7d5..3df5ddc5 100644 --- a/gdtoolkit/formatter/function_statement_to_str.py +++ b/gdtoolkit/formatter/function_statement_to_str.py @@ -12,7 +12,7 @@ def function_statement_to_str(statement: Tree) -> str: "func_var_stmt": lambda s: function_statement_to_str(s.children[0]), "const_stmt": lambda s: function_statement_to_str(s.children[0]), "expr_stmt": lambda s: expression_to_str(s.children[0]), # TODO: standalone? - "return_stmt": lambda s: f"return {standalone_expression_to_str(s.children[0])}", + "return_stmt": lambda s: "return" if len(s.children) == 0 else f"return {standalone_expression_to_str(s.children[0])}", "break_stmt": _not_implemented, "breakpoint_stmt": lambda _: "breakpoint", "continue_stmt": _not_implemented,