mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
parser: fix "else" followed by "comptime"
This commit is contained in:
parent
d5fc3c635a
commit
87733171b6
@ -956,7 +956,14 @@ fn expectStatement(p: *Parse, allow_defer_var: bool) Error!Node.Index {
|
||||
} else {
|
||||
const assign = try p.expectAssignExpr();
|
||||
try p.expectSemicolon(.expected_semi_after_stmt, true);
|
||||
return assign;
|
||||
return p.addNode(.{
|
||||
.tag = .@"comptime",
|
||||
.main_token = comptime_token,
|
||||
.data = .{
|
||||
.lhs = assign,
|
||||
.rhs = undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4376,6 +4376,21 @@ test "zig fmt: invalid doc comments on comptime and test blocks" {
|
||||
});
|
||||
}
|
||||
|
||||
test "zig fmt: else comptime expr" {
|
||||
try testCanonical(
|
||||
\\comptime {
|
||||
\\ if (true) {} else comptime foo();
|
||||
\\}
|
||||
\\comptime {
|
||||
\\ while (true) {} else comptime foo();
|
||||
\\}
|
||||
\\comptime {
|
||||
\\ for ("") |_| {} else comptime foo();
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: invalid else branch statement" {
|
||||
try testError(
|
||||
\\comptime {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user