std.zig.parser special cased error in return.

Related #909
This allows parsing of `std/special/build_runner.zig`
This commit is contained in:
Jimmi Holst Christensen 2018-04-11 20:56:05 +02:00
parent a7f77d7c6a
commit 5b584e06e3

View File

@ -2354,6 +2354,16 @@ pub const Parser = struct {
continue;
},
else => {
// TODO: this is a special case. Remove this when #760 is fixed
if (token.id == Token.Id.Keyword_error) {
if (self.isPeekToken(Token.Id.LBrace)) {
fn_proto.return_type = ast.NodeFnProto.ReturnType {
.Explicit = &(try self.createLiteral(arena, ast.NodeErrorType, token)).base
};
continue;
}
}
self.putBackToken(token);
fn_proto.return_type = ast.NodeFnProto.ReturnType { .Explicit = undefined };
stack.append(State {
@ -5185,3 +5195,13 @@ test "zig fmt: string identifier" {
\\
);
}
test "zig fmt: error return" {
try testCanonical(
\\fn err() error {
\\ call();
\\ return error.InvalidArgs;
\\}
\\
);
}