commit 272ae0ca0dff89689ad9715a4d8fa98ed86440b9 (tree)
parent 34cb5934ddd7c79fb96ffed87768764247740260
Author: Vincent Rischmann <vincent@rischmann.fr>
Date: Sat, 6 Mar 2021 19:37:33 +0100
fix parsing of assignment with 'inline for' and 'inline while'
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig
@@ -1981,7 +1981,7 @@ const Parser = struct {
}
},
.keyword_inline => {
- p.tok_i += 2;
+ p.tok_i += 1;
switch (p.token_tags[p.tok_i]) {
.keyword_for => return p.parseForExpr(),
.keyword_while => return p.parseWhileExpr(),
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
@@ -4297,6 +4297,18 @@ test "zig fmt: respect extra newline between switch items" {
);
}
+test "zig fmt: assignment with inline for and inline while" {
+ try testCanonical(
+ \\const tmp = inline for (items) |item| {};
+ \\
+ );
+
+ try testCanonical(
+ \\const tmp2 = inline while (true) {};
+ \\
+ );
+}
+
test "zig fmt: insert trailing comma if there are comments between switch values" {
try testTransform(
\\const a = switch (b) {