From 45634851de92f7848b648a0e009247e7f102e9ff Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 22 Feb 2021 23:51:15 +0100 Subject: [PATCH] zig fmt: fix firstToken() for extern fn_protos --- lib/std/zig/ast.zig | 11 ++++++----- lib/std/zig/parser_test.zig | 36 ++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 7b0380dfaf..40bb2256ec 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -366,10 +366,6 @@ pub const Tree = struct { .@"nosuspend", .asm_simple, .@"asm", - .fn_proto_simple, - .fn_proto_multi, - .fn_proto_one, - .fn_proto, .array_type, .array_type_sentinel, .error_value, @@ -449,7 +445,12 @@ pub const Tree = struct { .error_union, => n = datas[n].lhs, - .fn_decl => { + .fn_decl, + .fn_proto_simple, + .fn_proto_multi, + .fn_proto_one, + .fn_proto, + => { var i = main_tokens[n]; // fn token while (i > 0) { i -= 1; diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 42df500ddc..7bae2f3162 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -3727,24 +3727,24 @@ test "zig fmt: Don't add extra newline after if" { ); } -//test "zig fmt: comments in ternary ifs" { -// try testCanonical( -// \\const x = if (true) { -// \\ 1; -// \\} else if (false) -// \\ // Comment -// \\ 0; -// \\const y = if (true) -// \\ // Comment -// \\ 1 -// \\else -// \\ 0; -// \\ -// \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; -// \\ -// ); -//} -// +test "zig fmt: comments in ternary ifs" { + try testCanonical( + \\const x = if (true) { + \\ 1; + \\} else if (false) + \\ // Comment + \\ 0; + \\const y = if (true) + \\ // Comment + \\ 1 + \\else + \\ 0; + \\ + \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; + \\ + ); +} + //test "zig fmt: test comments in field access chain" { // try testCanonical( // \\pub const str = struct {