parser: require block in suspend expression

This commit is contained in:
g-w1
2021-07-15 03:55:22 -04:00
committed by GitHub
parent 4ea7470417
commit ee173d5127
3 changed files with 3 additions and 31 deletions

View File

@@ -885,11 +885,7 @@ const Parser = struct {
},
.keyword_suspend => {
const token = p.nextToken();
// TODO remove this special case when 0.9.0 is released.
const block_expr: Node.Index = if (p.eatToken(.semicolon) != null)
0
else
try p.expectBlockExprStatement();
const block_expr = try p.expectBlockExprStatement();
return p.addNode(.{
.tag = .@"suspend",
.main_token = token,

View File

@@ -92,21 +92,6 @@ test "zig fmt: rewrite callconv(.Inline) to the inline keyword" {
);
}
// TODO Remove this after zig 0.9.0 is released.
test "zig fmt: rewrite suspend without block expression" {
try testTransform(
\\fn foo() void {
\\ suspend;
\\}
\\
,
\\fn foo() void {
\\ suspend {}
\\}
\\
);
}
// TODO Remove this after zig 0.9.0 is released.
test "zig fmt: rewrite @byteOffsetOf to @offsetOf" {
try testTransform(

View File

@@ -275,17 +275,8 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
.@"suspend" => {
const suspend_token = main_tokens[node];
const body = datas[node].lhs;
if (body != 0) {
try renderToken(ais, tree, suspend_token, .space);
return renderExpression(gpa, ais, tree, body, space);
} else {
// TODO remove this special case when 0.9.0 is released.
assert(space == .semicolon);
try renderToken(ais, tree, suspend_token, .space);
try ais.writer().writeAll("{}");
try ais.insertNewline();
return;
}
try renderToken(ais, tree, suspend_token, .space);
return renderExpression(gpa, ais, tree, body, space);
},
.@"catch" => {