motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 010c58e3038ad9ca898b4c6e76877e4e7c43968f (tree)
parent 51682717d773aa4bdee89bc67cab08dc9b4bcc15
Author: Vexu <git@vexu.eu>
Date:   Sat, 30 May 2020 23:07:04 +0300

fix zig fmt out of bounds on empty file

Diffstat:
Mlib/std/zig/parser_test.zig | 6++++++
Mlib/std/zig/render.zig | 2++
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -223,6 +223,12 @@ test "recovery: missing block after for/while loops" { }); } +test "zig fmt: empty file" { + try testCanonical( + \\ + ); +} + test "zig fmt: if statment" { try testCanonical( \\test "" { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig @@ -82,6 +82,8 @@ fn renderRoot( var start_col: usize = 0; var decl_i: ast.NodeIndex = 0; const root_decls = tree.root_node.decls(); + + if (root_decls.len == 0) return; while (true) { var decl = root_decls[decl_i];