Skip to content

Commit 9898e8a

Browse files
Vexumatu3ba
authored andcommitted
AstGen: add note pointing to tuple field
Closes ziglang#14188
1 parent c2e6754 commit 9898e8a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/AstGen.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4487,9 +4487,24 @@ fn structDeclInner(
44874487
.container_field_align,
44884488
.container_field,
44894489
.@"comptime",
4490+
.test_decl,
44904491
=> continue,
44914492
else => {
4492-
return astgen.failNode(member_node, "tuple declarations cannot contain declarations", .{});
4493+
const tuple_member = for (container_decl.ast.members) |maybe_tuple| switch (node_tags[maybe_tuple]) {
4494+
.container_field_init,
4495+
.container_field_align,
4496+
.container_field,
4497+
=> break maybe_tuple,
4498+
else => {},
4499+
} else unreachable;
4500+
return astgen.failNodeNotes(
4501+
member_node,
4502+
"tuple declarations cannot contain declarations",
4503+
.{},
4504+
&[_]u32{
4505+
try astgen.errNoteNode(tuple_member, "tuple field here", .{}),
4506+
},
4507+
);
44934508
},
44944509
}
44954510
};

test/cases/compile_errors/tuple_declarations.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ const T = struct {
2323
// :5:5: error: union field missing name
2424
// :8:5: error: tuple field has a name
2525
// :15:5: error: tuple declarations cannot contain declarations
26+
// :12:5: note: tuple field here

0 commit comments

Comments
 (0)