diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index 848134cbdc..ac05cc321f 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -66,9 +66,9 @@ pub fn parse(gpa: *Allocator, source: []const u8) Allocator.Error!Tree { }); const root_members = try parser.parseContainerMembers(); const root_decls = try root_members.toSpan(&parser); - // parseContainerMembers will try to skip as much invalid tokens as - // it can, so we are now at EOF. - assert(parser.token_tags[parser.tok_i] == .eof); + if (parser.token_tags[parser.tok_i] != .eof) { + try parser.warnExpected(.eof); + } parser.nodes.items(.data)[0] = .{ .lhs = root_decls.start, .rhs = root_decls.end, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index d5dbd52190..b2562072f5 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -4187,20 +4187,21 @@ test "recovery: invalid container members" { }); } -//test "recovery: extra '}' at top level" { -// try testError( -// \\}}} -// \\test "" { -// \\ a && b; -// \\} -// , &[_]Error{ -// .expected_container_members, -// .expected_container_members, -// .expected_container_members, -// .invalid_and, -// }); -//} -// +// TODO after https://github.com/ziglang/zig/issues/35 is implemented, +// we should be able to recover from this *at any indentation level*, +// reporting a parse error and yet also parsing all the decls even +// inside structs. +test "recovery: extra '}' at top level" { + try testError( + \\}}} + \\test "" { + \\ a && b; + \\} + , &[_]Error{ + .expected_token, + }); +} + test "recovery: mismatched bracket at top level" { try testError( \\const S = struct {