Skip to content

Commit 5b584e0

Browse files
committed
std.zig.parser special cased error in return.
Related #909 This allows parsing of `std/special/build_runner.zig`
1 parent a7f77d7 commit 5b584e0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

std/zig/parser.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,16 @@ pub const Parser = struct {
23542354
continue;
23552355
},
23562356
else => {
2357+
// TODO: this is a special case. Remove this when #760 is fixed
2358+
if (token.id == Token.Id.Keyword_error) {
2359+
if (self.isPeekToken(Token.Id.LBrace)) {
2360+
fn_proto.return_type = ast.NodeFnProto.ReturnType {
2361+
.Explicit = &(try self.createLiteral(arena, ast.NodeErrorType, token)).base
2362+
};
2363+
continue;
2364+
}
2365+
}
2366+
23572367
self.putBackToken(token);
23582368
fn_proto.return_type = ast.NodeFnProto.ReturnType { .Explicit = undefined };
23592369
stack.append(State {
@@ -5185,3 +5195,13 @@ test "zig fmt: string identifier" {
51855195
\\
51865196
);
51875197
}
5198+
5199+
test "zig fmt: error return" {
5200+
try testCanonical(
5201+
\\fn err() error {
5202+
\\ call();
5203+
\\ return error.InvalidArgs;
5204+
\\}
5205+
\\
5206+
);
5207+
}

0 commit comments

Comments
 (0)