Commit 45634851de

Isaac Freund <ifreund@ifreund.xyz>
2021-02-22 23:51:15
zig fmt: fix firstToken() for extern fn_protos
1 parent 550688f
Changed files (2)
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;
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 {