authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2021-03-06 19:37:33+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-06 17:39:54-08:00
log272ae0ca0dff89689ad9715a4d8fa98ed86440b9
tree3c1ab7b65156f417b88f85768b54ef6ec70811fa
parent34cb5934ddd7c79fb96ffed87768764247740260

fix parsing of assignment with 'inline for' and 'inline while'


2 files changed, 13 insertions(+), 1 deletions(-)

lib/std/zig/parse.zig+1-1
...@@ -1981,7 +1981,7 @@ const Parser = struct {...@@ -1981,7 +1981,7 @@ const Parser = struct {
1981 }1981 }
1982 },1982 },
1983 .keyword_inline => {1983 .keyword_inline => {
1984 p.tok_i += 2;1984 p.tok_i += 1;
1985 switch (p.token_tags[p.tok_i]) {1985 switch (p.token_tags[p.tok_i]) {
1986 .keyword_for => return p.parseForExpr(),1986 .keyword_for => return p.parseForExpr(),
1987 .keyword_while => return p.parseWhileExpr(),1987 .keyword_while => return p.parseWhileExpr(),
lib/std/zig/parser_test.zig+12
...@@ -4297,6 +4297,18 @@ test "zig fmt: respect extra newline between switch items" {...@@ -4297,6 +4297,18 @@ test "zig fmt: respect extra newline between switch items" {
4297 );4297 );
4298}4298}
42994299
4300test "zig fmt: assignment with inline for and inline while" {
4301 try testCanonical(
4302 \\const tmp = inline for (items) |item| {};
4303 \\
4304 );
4305
4306 try testCanonical(
4307 \\const tmp2 = inline while (true) {};
4308 \\
4309 );
4310}
4311
4300test "zig fmt: insert trailing comma if there are comments between switch values" {4312test "zig fmt: insert trailing comma if there are comments between switch values" {
4301 try testTransform(4313 try testTransform(
4302 \\const a = switch (b) {4314 \\const a = switch (b) {