diff --git a/parser.c b/parser.c index bf476553dc..a1e9e8b8cf 100644 --- a/parser.c +++ b/parser.c @@ -982,8 +982,8 @@ static AstNodeIndex parseVarDeclProto(Parser* p) { } static AstTokenIndex parseBreakLabel(Parser* p) { - if (eatToken(p, TOKEN_COLON) == null_node) - return null_node; + if (eatToken(p, TOKEN_COLON) == null_token) + return null_token; return expectToken(p, TOKEN_IDENTIFIER); } @@ -1609,7 +1609,7 @@ static Members parseContainerMembers(Parser* p) { = (p->token_tags[p->tok_i] == TOKEN_STRING_LITERAL || p->token_tags[p->tok_i] == TOKEN_IDENTIFIER) ? nextToken(p) - : 0; + : null_token; const AstNodeIndex body = parseBlock(p); assert(body != 0); const AstNodeIndex test_decl = addNode(&p->nodes, diff --git a/parser_test.zig b/parser_test.zig index cfbc4946ad..56adc8ff50 100644 --- a/parser_test.zig +++ b/parser_test.zig @@ -873,3 +873,62 @@ test "zig fmt: remove empty lines at start/end of container decl" { \\ ); } + +test "zig fmt: allow empty line before comment at start of block" { + try testCanonical( + \\test { + \\ + \\ // foo + \\ const x = 42; + \\} + \\ + ); +} + +test "zig fmt: comptime struct field" { + try testCanonical( + \\const Foo = struct { + \\ a: i32, + \\ comptime b: i32 = 1234, + \\}; + \\ + ); +} + +test "zig fmt: break from block" { + try testCanonical( + \\const a = blk: { + \\ break :blk 42; + \\}; + \\const b = blk: { + \\ break :blk; + \\}; + \\const c = { + \\ break 42; + \\}; + \\const d = { + \\ break; + \\}; + \\ + ); +} + +test "zig fmt: grouped expressions (parentheses)" { + try testCanonical( + \\const r = (x + y) * (a + b); + \\ + ); +} + +test "zig fmt: array types last token" { + try testCanonical( + \\test { + \\ const x = [40]u32; + \\} + \\ + \\test { + \\ const x = [40:0]u32; + \\} + \\ + ); +}