From 405a2390f09c78fb5db435e97d8ff23c0b44753b Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Tue, 10 Apr 2018 22:44:55 -0400 Subject: [PATCH] zig fmt while-else with no blocks --- std/zig/parser.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/std/zig/parser.zig b/std/zig/parser.zig index 5d5b1ceab..11b551fec 100644 --- a/std/zig/parser.zig +++ b/std/zig/parser.zig @@ -3839,12 +3839,13 @@ pub const Parser = struct { }, ast.Node.Id.Else => { const else_node = @fieldParentPtr(ast.NodeElse, "base", base); - try stream.print("{} ", self.tokenizer.getTokenSlice(else_node.else_token)); + try stream.print("{}", self.tokenizer.getTokenSlice(else_node.else_token)); switch (else_node.body.id) { ast.Node.Id.Block, ast.Node.Id.If, ast.Node.Id.For, ast.Node.Id.While, ast.Node.Id.Switch => { + try stream.print(" "); try stack.append(RenderState { .Expression = else_node.body }); }, else => { @@ -4805,6 +4806,11 @@ test "zig fmt: while" { \\ unreachable; \\ }; \\ + \\ const res = while (0 < 10) + \\ break 7 + \\ else + \\ unreachable; + \\ \\ var a: error!u8 = 0; \\ while (a) |v| { \\ a = error.Err;