Commit f962315363
Changed files (2)
lib
std
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 {