Commit f962315363

Vexu <git@vexu.eu>
2020-07-30 11:58:32
fix missing parser error for missing comma before eof
Closes #5952
1 parent 1f8f434
Changed files (2)
lib/std/zig/parse.zig
@@ -201,7 +201,16 @@ const Parser = struct {
                     p.findNextContainerMember();
                     const next = p.token_ids[p.tok_i];
                     switch (next) {
-                        .Eof => break,
+                        .Eof => {
+                            // no invalid tokens were found
+                            if (index == p.tok_i) break;
+
+                            // Invalid tokens, add error and exit
+                            try p.errors.append(p.gpa, .{
+                                .ExpectedToken = .{ .token = index, .expected_id = .Comma },
+                            });
+                            break;
+                        },
                         else => {
                             if (next == .RBrace) {
                                 if (!top_level) break;
lib/std/zig/parser_test.zig
@@ -293,6 +293,14 @@ test "zig fmt: decl between fields" {
     });
 }
 
+test "zig fmt: eof after missing comma" {
+    try testError(
+        \\foo()
+    , &[_]Error{
+        .ExpectedToken,
+    });
+}
+
 test "zig fmt: errdefer with payload" {
     try testCanonical(
         \\pub fn main() anyerror!void {