return a valid node even if invalid deref was used

This commit is contained in:
Vexu 2020-10-29 19:20:15 +02:00
parent d7f9128b5d
commit a63fd34c50
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 17 additions and 4 deletions

View File

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

View File

@ -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,
});
}