zig fmt: fix 2 bugs of mangling source files

master
Andrew Kelley 2019-05-29 18:54:46 -04:00
parent b7a82288ad
commit 8a4ee5942b
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 34 additions and 2 deletions

View File

@ -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}")

View File

@ -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,
};

View File

@ -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;

View File

@ -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,
}
},