Commit bc24b86d82

Lachlan Easton <lachlan@lakebythewoods.xyz>
2020-09-01 05:19:34
zig fmt: Fix regression not covered by testing
1 parent 029ec45
Changed files (2)
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
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;