Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5360,8 +5360,6 @@ fn tupleDecl(
const gpa = astgen.gpa;
const tree = astgen.tree;

const node_tags = tree.nodes.items(.tag);

switch (layout) {
.auto => {},
.@"extern", .@"packed" => return astgen.failNode(node, "{s} tuples are not supported", .{@tagName(layout)}),
Expand All @@ -5383,12 +5381,9 @@ fn tupleDecl(

for (container_decl.ast.members) |member_node| {
const field = tree.fullContainerField(member_node) orelse {
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 => {},
const tuple_member = for (container_decl.ast.members) |maybe_tuple| {
if ((tree.fullContainerField(maybe_tuple) orelse continue).ast.tuple_like)
break maybe_tuple;
} else unreachable;
return astgen.failNodeNotes(
member_node,
Expand All @@ -5399,7 +5394,16 @@ fn tupleDecl(
};

if (!field.ast.tuple_like) {
return astgen.failTok(field.ast.main_token, "tuple field has a name", .{});
const tuple_member = for (container_decl.ast.members) |maybe_tuple| {
if ((tree.fullContainerField(maybe_tuple) orelse continue).ast.tuple_like)
break maybe_tuple;
} else unreachable;
return astgen.failTokNotes(
field.ast.main_token,
"tuple field has a name",
.{},
&.{try astgen.errNoteNode(tuple_member, "tuple field here", .{})},
);
}

if (field.ast.align_expr != 0) {
Expand Down
10 changes: 10 additions & 0 deletions test/cases/compile_errors/tuple_declarations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ const T = struct {
const a = 1;
};

const T2 = struct {
const a = 1;

b: u32,
[]const u8,
};

// error
// backend=stage2
// target=native
//
// :2:5: error: enum field missing name
// :5:5: error: union field missing name
// :8:5: error: tuple field has a name
// :9:5: note: tuple field here
// :15:5: error: tuple declarations cannot contain declarations
// :12:5: note: tuple field here
// :19:5: error: tuple declarations cannot contain declarations
// :22:5: note: tuple field here