From 2dc5993a2908f175c18f5b241cd01162ac0aa758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 10 Feb 2026 18:39:13 +0000 Subject: [PATCH] parser: port if-condition-wraps tests, implement catch payload Port tests: - "if condition has line break but must not wrap" - "if condition has line break but must not wrap (no fn call comma)" Implement catch payload (|err|) parsing in parseExprPrecedence. Co-Authored-By: Claude Opus 4.6 (1M context) --- parser.c | 7 ++----- parser_test.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/parser.c b/parser.c index fed9091395..f256934677 100644 --- a/parser.c +++ b/parser.c @@ -1744,11 +1744,8 @@ static AstNodeIndex parseExprPrecedence(Parser* p, int32_t min_prec) { assert(info.prec != banned_prec); const AstTokenIndex oper_token = nextToken(p); - if (tok_tag == TOKEN_KEYWORD_CATCH) { - fprintf(stderr, "parsePayload not supported\n"); - exit(1); - return 0; // tcc - } + if (tok_tag == TOKEN_KEYWORD_CATCH) + parsePayload(p); const AstNodeIndex rhs = parseExprPrecedence(p, info.prec + 1); assert(rhs != 0); diff --git a/parser_test.zig b/parser_test.zig index a9e53ddf20..09ec6fbd77 100644 --- a/parser_test.zig +++ b/parser_test.zig @@ -2009,6 +2009,51 @@ test "zig fmt: if condition wraps" { ); } +test "zig fmt: if condition has line break but must not wrap" { + try testCanonical( + \\comptime { + \\ if (self.user_input_options.put( + \\ name, + \\ UserInputOption{ + \\ .name = name, + \\ .used = false, + \\ }, + \\ ) catch unreachable) |*prev_value| { + \\ foo(); + \\ bar(); + \\ } + \\ if (put( + \\ a, + \\ b, + \\ )) { + \\ foo(); + \\ } + \\} + \\ + ); +} + +test "zig fmt: if condition has line break but must not wrap (no fn call comma)" { + try testCanonical( + \\comptime { + \\ if (self.user_input_options.put(name, UserInputOption{ + \\ .name = name, + \\ .used = false, + \\ }) catch unreachable) |*prev_value| { + \\ foo(); + \\ bar(); + \\ } + \\ if (put( + \\ a, + \\ b, + \\ )) { + \\ foo(); + \\ } + \\} + \\ + ); +} + test "zig fmt: pointer of unknown length" { try testCanonical( \\fn foo(ptr: [*]u8) void {}