Prevent unreachable when file ends with struct field

This commit is contained in:
hryx 2019-07-05 00:36:34 -07:00 committed by Andrew Kelley
parent 9471f16c79
commit 7f618184ad
2 changed files with 10 additions and 1 deletions

View File

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

View File

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