Commit 7f618184ad

hryx <codroid@gmail.com>
2019-07-05 09:36:34
Prevent unreachable when file ends with struct field
1 parent 9471f16
Changed files (2)
std/zig/parser_test.zig
@@ -2258,6 +2258,15 @@ test "zig fmt: if type expr" {
     );
 }
 
+test "zig fmt: file ends with struct field" {
+    try testTransform(
+        \\a: bool
+    ,
+        \\a: bool,
+        \\
+    );
+}
+
 const std = @import("std");
 const mem = std.mem;
 const warn = std.debug.warn;
std/zig/render.zig
@@ -1899,7 +1899,7 @@ fn renderTokenOffset(
             return renderToken(tree, stream, token_index + 1, indent, start_col, Space.Newline);
         },
         else => {
-            if (tree.tokens.at(token_index + 2).id == Token.Id.MultilineStringLiteralLine) {
+            if (token_index + 2 < tree.tokens.len and tree.tokens.at(token_index + 2).id == Token.Id.MultilineStringLiteralLine) {
                 try stream.write(",");
                 return;
             } else {