authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-30 12:58:32+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-30 13:10:55+03:00
logf962315363b6306f819b7c88b830ea00ab0e734e
tree7241f0b0df1d24f09b277d49878c3575f1cc525a
parent1f8f434b9c672837d307b50d0fb3c87b8a0ec16a
signaturelock-open Commit is signed but in an unrecognized format.

fix missing parser error for missing comma before eof

Closes #5952

2 files changed, 18 insertions(+), 1 deletions(-)

lib/std/zig/parse.zig+10-1
...@@ -201,7 +201,16 @@ const Parser = struct {...@@ -201,7 +201,16 @@ const Parser = struct {
201 p.findNextContainerMember();201 p.findNextContainerMember();
202 const next = p.token_ids[p.tok_i];202 const next = p.token_ids[p.tok_i];
203 switch (next) {203 switch (next) {
204 .Eof => break,204 .Eof => {
205 // no invalid tokens were found
206 if (index == p.tok_i) break;
207
208 // Invalid tokens, add error and exit
209 try p.errors.append(p.gpa, .{
210 .ExpectedToken = .{ .token = index, .expected_id = .Comma },
211 });
212 break;
213 },
205 else => {214 else => {
206 if (next == .RBrace) {215 if (next == .RBrace) {
207 if (!top_level) break;216 if (!top_level) break;
lib/std/zig/parser_test.zig+8
...@@ -293,6 +293,14 @@ test "zig fmt: decl between fields" {...@@ -293,6 +293,14 @@ test "zig fmt: decl between fields" {
293 });293 });
294}294}
295295
296test "zig fmt: eof after missing comma" {
297 try testError(
298 \\foo()
299 , &[_]Error{
300 .ExpectedToken,
301 });
302}
303
296test "zig fmt: errdefer with payload" {304test "zig fmt: errdefer with payload" {
297 try testCanonical(305 try testCanonical(
298 \\pub fn main() anyerror!void {306 \\pub fn main() anyerror!void {