Commit 8a4ee5942b

Andrew Kelley <andrew@ziglang.org>
2019-05-30 00:54:46
zig fmt: fix 2 bugs of mangling source files
1 parent b7a8228
std/zig/parse.zig
@@ -1026,7 +1026,7 @@ fn parseWhileExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
         else_node.* = Node.Else{
             .base = Node{ .id = .Else },
             .else_token = else_token,
-            .payload = null,
+            .payload = payload,
             .body = body,
         };
 
std/zig/parser_test.zig
@@ -8,6 +8,35 @@ test "zig fmt: change use to usingnamespace" {
     );
 }
 
+test "zig fmt: while else err prong with no block" {
+    try testCanonical(
+        \\test "" {
+        \\    const result = while (returnError()) |value| {
+        \\        break value;
+        \\    } else |err| i32(2);
+        \\    expect(result == 2);
+        \\}
+        \\
+    );
+}
+
+test "zig fmt: tagged union with enum values" {
+    try testCanonical(
+        \\const MultipleChoice2 = union(enum(u32)) {
+        \\    Unspecified1: i32,
+        \\    A: f32 = 20,
+        \\    Unspecified2: void,
+        \\    B: bool = 40,
+        \\    Unspecified3: i32,
+        \\    C: i8 = 60,
+        \\    Unspecified4: void,
+        \\    D: void = 1000,
+        \\    Unspecified5: i32,
+        \\};
+        \\
+    );
+}
+
 test "zig fmt: allowzero pointer" {
     try testCanonical(
         \\const T = [*]allowzero const u8;
std/zig/render.zig
@@ -214,7 +214,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
                 try renderToken(tree, stream, field.name_token, indent, start_col, Space.None); // name
                 try renderToken(tree, stream, tree.nextToken(field.name_token), indent, start_col, Space.Space); // :
                 try renderExpression(allocator, stream, tree, indent, start_col, field.type_expr.?, Space.Space); // type
-                try renderToken(tree, stream, tree.nextToken(field.name_token), indent, start_col, Space.Space); // =
+                try renderToken(tree, stream, tree.nextToken(field.type_expr.?.lastToken()), indent, start_col, Space.Space); // =
                 return renderExpression(allocator, stream, tree, indent, start_col, field.value_expr.?, Space.Comma); // value,
             }
         },
CMakeLists.txt
@@ -6729,6 +6729,9 @@ add_custom_command(
         "${CMAKE_SOURCE_DIR}/src-self-hosted/stage1.zig"
         "${CMAKE_SOURCE_DIR}/src-self-hosted/translate_c.zig"
         "${CMAKE_SOURCE_DIR}/build.zig"
+        "${CMAKE_SOURCE_DIR}/std/zig/parse.zig"
+        "${CMAKE_SOURCE_DIR}/std/zig/render.zig"
+        "${CMAKE_SOURCE_DIR}/std/zig/tokenizer.zig"
 )
 add_custom_target(userland_target DEPENDS "${LIBUSERLAND}")
 add_executable(zig "${ZIG_MAIN_SRC}")