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 {...@@ -91,9 +91,6 @@ const Parser = struct {
91 extra_data: std.ArrayListUnmanaged(Node.Index),91 extra_data: std.ArrayListUnmanaged(Node.Index),
92 scratch: std.ArrayListUnmanaged(Node.Index),92 scratch: std.ArrayListUnmanaged(Node.Index),
9393
94 /// Used for the error note of decl_between_fields error.
95 last_field: TokenIndex = undefined,
96
97 const SmallSpan = union(enum) {94 const SmallSpan = union(enum) {
98 zero_or_one: Node.Index,95 zero_or_one: Node.Index,
99 multi: Node.SubRange,96 multi: Node.SubRange,
...@@ -252,6 +249,8 @@ const Parser = struct {...@@ -252,6 +249,8 @@ const Parser = struct {
252 err,249 err,
253 } = .none;250 } = .none;
254251
252 var last_field: TokenIndex = undefined;
253
255 // Skip container doc comments.254 // Skip container doc comments.
256 while (p.eatToken(.container_doc_comment)) |_| {}255 while (p.eatToken(.container_doc_comment)) |_| {}
257256
...@@ -274,7 +273,7 @@ const Parser = struct {...@@ -274,7 +273,7 @@ const Parser = struct {
274 .identifier => {273 .identifier => {
275 p.tok_i += 1;274 p.tok_i += 1;
276 const identifier = p.tok_i;275 const identifier = p.tok_i;
277 defer p.last_field = identifier;276 defer last_field = identifier;
278 const container_field = try p.expectContainerFieldRecoverable();277 const container_field = try p.expectContainerFieldRecoverable();
279 if (container_field != 0) {278 if (container_field != 0) {
280 switch (field_state) {279 switch (field_state) {
...@@ -288,7 +287,7 @@ const Parser = struct {...@@ -288,7 +287,7 @@ const Parser = struct {
288 try p.warnMsg(.{287 try p.warnMsg(.{
289 .tag = .previous_field,288 .tag = .previous_field,
290 .is_note = true,289 .is_note = true,
291 .token = p.last_field,290 .token = last_field,
292 });291 });
293 try p.warnMsg(.{292 try p.warnMsg(.{
294 .tag = .next_field,293 .tag = .next_field,
...@@ -389,7 +388,7 @@ const Parser = struct {...@@ -389,7 +388,7 @@ const Parser = struct {
389 },388 },
390 .identifier => {389 .identifier => {
391 const identifier = p.tok_i;390 const identifier = p.tok_i;
392 defer p.last_field = identifier;391 defer last_field = identifier;
393 const container_field = try p.expectContainerFieldRecoverable();392 const container_field = try p.expectContainerFieldRecoverable();
394 if (container_field != 0) {393 if (container_field != 0) {
395 switch (field_state) {394 switch (field_state) {
...@@ -402,7 +401,7 @@ const Parser = struct {...@@ -402,7 +401,7 @@ const Parser = struct {
402 });401 });
403 try p.warnMsg(.{402 try p.warnMsg(.{
404 .tag = .previous_field,403 .tag = .previous_field,
405 .token = p.last_field,404 .token = last_field,
406 });405 });
407 try p.warnMsg(.{406 try p.warnMsg(.{
408 .tag = .next_field,407 .tag = .next_field,
test/compile_errors.zig+6-3
...@@ -866,7 +866,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -866,7 +866,10 @@ pub fn addCases(ctx: *TestContext) !void {
866 \\ const foo = 2;866 \\ const foo = 2;
867 \\ const bar = 2;867 \\ const bar = 2;
868 \\ const baz = 2;868 \\ const baz = 2;
869 \\ a: usize,869 \\ a: struct {
870 \\ a: u32,
871 \\ b: u32,
872 \\ },
870 \\ const foo1 = 2;873 \\ const foo1 = 2;
871 \\ const bar1 = 2;874 \\ const bar1 = 2;
872 \\ const baz1 = 2;875 \\ const baz1 = 2;
...@@ -876,9 +879,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -876,9 +879,9 @@ pub fn addCases(ctx: *TestContext) !void {
876 \\ _ = S;879 \\ _ = S;
877 \\}880 \\}
878 , &[_][]const u8{881 , &[_][]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",
880 "tmp.zig:5:5: note: field before declarations here",883 "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",
882 });885 });
883886
884 ctx.objErrStage1("non-extern function with var args",887 ctx.objErrStage1("non-extern function with var args",