Commit 5b584e06e3

Jimmi Holst Christensen <rainbowhejsil@gmail.com>
2018-04-11 20:56:05
std.zig.parser special cased error in return. Related #909 This allows parsing of `std/special/build_runner.zig`
1 parent a7f77d7
Changed files (1)
std
std/zig/parser.zig
@@ -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;
+        \\}
+        \\
+    );
+}