parse.zig: make parseParamDeclList check for nonfinal varargs

This commit is contained in:
Matthew Borkowski
2021-05-30 02:24:44 -04:00
committed by Veikka Tuominen
parent 8bf04c3a69
commit ff0a15bb7a
3 changed files with 23 additions and 0 deletions

View File

@@ -3553,11 +3553,15 @@ const Parser = struct {
_ = try p.expectToken(.l_paren);
const scratch_top = p.scratch.items.len;
defer p.scratch.shrinkRetainingCapacity(scratch_top);
var varargs: union(enum){ none, seen, nonfinal: TokenIndex } = .none;
while (true) {
if (p.eatToken(.r_paren)) |_| break;
if (varargs == .seen) varargs = .{ .nonfinal = p.tok_i };
const param = try p.expectParamDecl();
if (param != 0) {
try p.scratch.append(p.gpa, param);
} else if (p.token_tags[p.tok_i - 1] == .ellipsis3) {
if (varargs == .none) varargs = .seen;
}
switch (p.token_tags[p.nextToken()]) {
.comma => {},
@@ -3574,6 +3578,9 @@ const Parser = struct {
},
}
}
if (varargs == .nonfinal) {
try p.warnMsg(.{ .tag = .varargs_nonfinal, .token = varargs.nonfinal });
}
const params = p.scratch.items[scratch_top..];
return switch (params.len) {
0 => SmallSpan { .zero_or_one = 0 },