Commit 2ed9288246
Changed files (2)
lib
std
lib/std/zig/parse.zig
@@ -1584,18 +1584,13 @@ const Parser = struct {
_ = p.nextToken();
const asterisk = p.nextToken();
var sentinel: Node.Index = 0;
- prefix: {
- if (p.eatToken(.identifier)) |ident| {
- const token_slice = p.source[p.token_starts[ident]..][0..2];
- if (!std.mem.eql(u8, token_slice, "c]")) {
- p.tok_i -= 1;
- } else {
- break :prefix;
- }
- }
- if (p.eatToken(.colon)) |_| {
- sentinel = try p.expectExpr();
+ if (p.eatToken(.identifier)) |ident| {
+ const ident_slice = p.source[p.token_starts[ident]..p.token_starts[ident + 1]];
+ if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.spaces), "c")) {
+ p.tok_i -= 1;
}
+ } else if (p.eatToken(.colon)) |_| {
+ sentinel = try p.expectExpr();
}
_ = try p.expectToken(.r_bracket);
const mods = try p.parsePtrModifiers();
lib/std/zig/parser_test.zig
@@ -5259,6 +5259,14 @@ test "recovery: nonfinal varargs" {
});
}
+test "recovery: eof in c pointer" {
+ try testError(
+ \\const Ptr = [*c
+ , &[_]Error{
+ .expected_token,
+ });
+}
+
const std = @import("std");
const mem = std.mem;
const print = std.debug.print;