Commit 1658e4893d

Veikka Tuominen <git@vexu.eu>
2023-01-10 14:07:48
AstGen: add note pointing to tuple field
Closes #14188
1 parent e2adf3b
Changed files (2)
src
test
cases
compile_errors
src/AstGen.zig
@@ -4487,9 +4487,24 @@ fn structDeclInner(
             .container_field_align,
             .container_field,
             .@"comptime",
+            .test_decl,
             => continue,
             else => {
-                return astgen.failNode(member_node, "tuple declarations cannot contain declarations", .{});
+                const tuple_member = for (container_decl.ast.members) |maybe_tuple| switch (node_tags[maybe_tuple]) {
+                    .container_field_init,
+                    .container_field_align,
+                    .container_field,
+                    => break maybe_tuple,
+                    else => {},
+                } else unreachable;
+                return astgen.failNodeNotes(
+                    member_node,
+                    "tuple declarations cannot contain declarations",
+                    .{},
+                    &[_]u32{
+                        try astgen.errNoteNode(tuple_member, "tuple field here", .{}),
+                    },
+                );
             },
         }
     };
test/cases/compile_errors/tuple_declarations.zig
@@ -23,3 +23,4 @@ const T = struct {
 // :5:5: error: union field missing name
 // :8:5: error: tuple field has a name
 // :15:5: error: tuple declarations cannot contain declarations
+// :12:5: note: tuple field here