fix missing parser error for missing comma before eof

Closes #5952
This commit is contained in:
Vexu
2020-07-30 12:58:32 +03:00
parent 1f8f434b9c
commit f962315363
2 changed files with 18 additions and 1 deletions

View File

@@ -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;

View File

@@ -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 {