authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-01-26 22:08:30+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-01-27 16:20:47+02:00
log87733171b60b0816e93c76419d10674ba10684e2
tree0f1cb734a8a1c367a969fbcac5d0157228633bac
parentd5fc3c635ad94b6934fb9b90549d7f36eb9fa56b

parser: fix "else" followed by "comptime"


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

lib/std/zig/Parse.zig+8-1
......@@ -956,7 +956,14 @@ fn expectStatement(p: *Parse, allow_defer_var: bool) Error!Node.Index {
956956 } else {
957957 const assign = try p.expectAssignExpr();
958958 try p.expectSemicolon(.expected_semi_after_stmt, true);
959 return assign;
959 return p.addNode(.{
960 .tag = .@"comptime",
961 .main_token = comptime_token,
962 .data = .{
963 .lhs = assign,
964 .rhs = undefined,
965 },
966 });
960967 }
961968 }
962969
lib/std/zig/parser_test.zig+15
......@@ -4376,6 +4376,21 @@ test "zig fmt: invalid doc comments on comptime and test blocks" {
43764376 });
43774377}
43784378
4379test "zig fmt: else comptime expr" {
4380 try testCanonical(
4381 \\comptime {
4382 \\ if (true) {} else comptime foo();
4383 \\}
4384 \\comptime {
4385 \\ while (true) {} else comptime foo();
4386 \\}
4387 \\comptime {
4388 \\ for ("") |_| {} else comptime foo();
4389 \\}
4390 \\
4391 );
4392}
4393
43794394test "zig fmt: invalid else branch statement" {
43804395 try testError(
43814396 \\comptime {