authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-19 10:10:32+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-19 10:15:54+02:00
log2f0204aca303daf899a97c740719a62398adc206
tree5382421eed459c511757efa5d32be9e3c19c9d26
parent2e1c16d64979c15604b90128fbd63d26ab4b796d

parser: fix "previous field here" pointing to wrong field


2 files changed, 12 insertions(+), 10 deletions(-)

lib/std/zig/parse.zig+6-7
......@@ -91,9 +91,6 @@ const Parser = struct {
9191 extra_data: std.ArrayListUnmanaged(Node.Index),
9292 scratch: std.ArrayListUnmanaged(Node.Index),
9393
94 /// Used for the error note of decl_between_fields error.
95 last_field: TokenIndex = undefined,
96
9794 const SmallSpan = union(enum) {
9895 zero_or_one: Node.Index,
9996 multi: Node.SubRange,
......@@ -252,6 +249,8 @@ const Parser = struct {
252249 err,
253250 } = .none;
254251
252 var last_field: TokenIndex = undefined;
253
255254 // Skip container doc comments.
256255 while (p.eatToken(.container_doc_comment)) |_| {}
257256
......@@ -274,7 +273,7 @@ const Parser = struct {
274273 .identifier => {
275274 p.tok_i += 1;
276275 const identifier = p.tok_i;
277 defer p.last_field = identifier;
276 defer last_field = identifier;
278277 const container_field = try p.expectContainerFieldRecoverable();
279278 if (container_field != 0) {
280279 switch (field_state) {
......@@ -288,7 +287,7 @@ const Parser = struct {
288287 try p.warnMsg(.{
289288 .tag = .previous_field,
290289 .is_note = true,
291 .token = p.last_field,
290 .token = last_field,
292291 });
293292 try p.warnMsg(.{
294293 .tag = .next_field,
......@@ -389,7 +388,7 @@ const Parser = struct {
389388 },
390389 .identifier => {
391390 const identifier = p.tok_i;
392 defer p.last_field = identifier;
391 defer last_field = identifier;
393392 const container_field = try p.expectContainerFieldRecoverable();
394393 if (container_field != 0) {
395394 switch (field_state) {
......@@ -402,7 +401,7 @@ const Parser = struct {
402401 });
403402 try p.warnMsg(.{
404403 .tag = .previous_field,
405 .token = p.last_field,
404 .token = last_field,
406405 });
407406 try p.warnMsg(.{
408407 .tag = .next_field,
test/compile_errors.zig+6-3
......@@ -866,7 +866,10 @@ pub fn addCases(ctx: *TestContext) !void {
866866 \\ const foo = 2;
867867 \\ const bar = 2;
868868 \\ const baz = 2;
869 \\ a: usize,
869 \\ a: struct {
870 \\ a: u32,
871 \\ b: u32,
872 \\ },
870873 \\ const foo1 = 2;
871874 \\ const bar1 = 2;
872875 \\ const baz1 = 2;
......@@ -876,9 +879,9 @@ pub fn addCases(ctx: *TestContext) !void {
876879 \\ _ = S;
877880 \\}
878881 , &[_][]const u8{
879 "tmp.zig:6:5: error: declarations are not allowed between container fields",
882 "tmp.zig:9:5: error: declarations are not allowed between container fields",
880883 "tmp.zig:5:5: note: field before declarations here",
881 "tmp.zig:9:5: note: field after declarations here",
884 "tmp.zig:12:5: note: field after declarations here",
882885 });
883886
884887 ctx.objErrStage1("non-extern function with var args",