From bc24b86d82ec3b8d7d6e7e5d2d3dceb82d7b53dc Mon Sep 17 00:00:00 2001 From: Lachlan Easton Date: Tue, 1 Sep 2020 13:19:34 +1000 Subject: zig fmt: Fix regression not covered by testing --- lib/std/io/auto_indenting_stream.zig | 4 +++- lib/std/zig/parser_test.zig | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/std') diff --git a/lib/std/io/auto_indenting_stream.zig b/lib/std/io/auto_indenting_stream.zig index e2233f8cc2..d4256324f1 100644 --- a/lib/std/io/auto_indenting_stream.zig +++ b/lib/std/io/auto_indenting_stream.zig @@ -106,7 +106,9 @@ pub fn AutoIndentingStream(comptime WriterType: type) type { pub fn popIndent(self: *Self) void { assert(self.indent_count != 0); self.indent_count -= 1; - self.indent_next_line = std.math.min(self.indent_count, self.indent_next_line); // Tentative indent may have been popped before there was a newline + + if (self.indent_next_line > 0) + self.indent_next_line -= 1; } /// Writes ' ' bytes if the current line is empty diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index f4da650efb..8652a73c50 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -3310,6 +3310,17 @@ test "zig fmt: Only indent multiline string literals in function calls" { ); } +test "zig fmt: Don't add extra newline after if" { + try testCanonical( + \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void { + \\ if (cwd().symLink(existing_path, new_path, .{})) { + \\ return; + \\ } + \\} + \\ + ); +} + const std = @import("std"); const mem = std.mem; const warn = std.debug.warn; -- cgit v1.2.3