| author | |
| committer | |
| log | 87733171b60b0816e93c76419d10674ba10684e2 |
| tree | 0f1cb734a8a1c367a969fbcac5d0157228633bac |
| parent | d5fc3c635ad94b6934fb9b90549d7f36eb9fa56b |
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 { |
| 956 | 956 | } else { |
| 957 | 957 | const assign = try p.expectAssignExpr(); |
| 958 | 958 | 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 | }); | |
| 960 | 967 | } |
| 961 | 968 | } |
| 962 | 969 |
lib/std/zig/parser_test.zig+15| ... | ... | @@ -4376,6 +4376,21 @@ test "zig fmt: invalid doc comments on comptime and test blocks" { |
| 4376 | 4376 | }); |
| 4377 | 4377 | } |
| 4378 | 4378 | |
| 4379 | test "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 | ||
| 4379 | 4394 | test "zig fmt: invalid else branch statement" { |
| 4380 | 4395 | try testError( |
| 4381 | 4396 | \\comptime { |