From a63fd34c50b032e4ed5136dba8b098f780d5b9f8 Mon Sep 17 00:00:00 2001 From: Vexu Date: Thu, 29 Oct 2020 19:20:15 +0200 Subject: [PATCH] return a valid node even if invalid deref was used --- lib/std/zig/parse.zig | 12 +++++++++--- lib/std/zig/parser_test.zig | 9 ++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index 5e745dd424..d36bf55ecd 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -2701,11 +2701,17 @@ const Parser = struct { return &node.base; } - if (p.token_ids[p.tok_i] == .Invalid_periodasterisks) { + if (p.eatToken(.Invalid_periodasterisks)) |period_asterisk| { try p.errors.append(p.gpa, .{ - .AsteriskAfterPointerDereference = .{ .token = p.tok_i }, + .AsteriskAfterPointerDereference = .{ .token = period_asterisk }, }); - return null; + const node = try p.arena.allocator.create(Node.SimpleSuffixOp); + node.* = .{ + .base = .{ .tag = .Deref }, + .lhs = lhs, + .rtoken = period_asterisk, + }; + return &node.base; } if (p.eatToken(.Period)) |period| { diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 9495f536d1..71642da453 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -226,7 +226,14 @@ test "recovery: invalid asterisk after pointer dereference" { \\} , &[_]Error{ .AsteriskAfterPointerDereference, - .ExpectedToken, + }); + try testError( + \\test "" { + \\ var sequence = "repeat".** 10&&a; + \\} + , &[_]Error{ + .AsteriskAfterPointerDereference, + .InvalidAnd, }); }