diff options
| author | Vexu <git@vexu.eu> | 2020-05-30 23:07:04 +0300 |
|---|---|---|
| committer | Vexu <git@vexu.eu> | 2020-05-30 23:07:51 +0300 |
| commit | 010c58e3038ad9ca898b4c6e76877e4e7c43968f (patch) | |
| tree | e2725b755bbcd63861b38fc22bab627483d774b8 /lib/std | |
| parent | 51682717d773aa4bdee89bc67cab08dc9b4bcc15 (diff) | |
| download | zig-010c58e3038ad9ca898b4c6e76877e4e7c43968f.tar.gz zig-010c58e3038ad9ca898b4c6e76877e4e7c43968f.zip | |
fix zig fmt out of bounds on empty file
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 6 | ||||
| -rw-r--r-- | lib/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 index 641ff37eea..c8e7abd5cb 100644 --- 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 index 79ab13e80e..54fa2e39f3 100644 --- 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]; |
