AstGen: fix incorrect source loc for duplicate enum tag

This commit is contained in:
Andrew Kelley 2021-04-07 20:50:57 -07:00
parent 12087d4cba
commit a62e19ec8e
2 changed files with 47 additions and 4 deletions

View File

@ -1999,14 +1999,14 @@ fn containerDecl(
// don't need to waste time with a hash map.
const bad_node = for (container_decl.ast.members) |other_member_node| {
const other_member = switch (node_tags[other_member_node]) {
.container_field_init => tree.containerFieldInit(member_node),
.container_field_align => tree.containerFieldAlign(member_node),
.container_field => tree.containerField(member_node),
.container_field_init => tree.containerFieldInit(other_member_node),
.container_field_align => tree.containerFieldAlign(other_member_node),
.container_field => tree.containerField(other_member_node),
else => unreachable, // We checked earlier.
};
const other_tag_name = try mod.identifierTokenStringTreeArena(
scope,
name_token,
other_member.ast.name_token,
tree,
arena,
);

View File

@ -631,6 +631,49 @@ pub fn addCases(ctx: *TestContext) !void {
":6:5: error: redundant non-exhaustive enum mark",
":3:5: note: other mark here",
});
case.addError(
\\const E1 = enum {
\\ a,
\\ b,
\\ c,
\\ _ = 10,
\\};
\\export fn foo() void {
\\ const x = E1.a;
\\}
, &.{
":5:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",
});
case.addError(
\\const E1 = enum {};
\\export fn foo() void {
\\ const x = E1.a;
\\}
, &.{
":1:12: error: enum declarations must have at least one tag",
});
case.addError(
\\const E1 = enum { a, b, _ };
\\export fn foo() void {
\\ const x = E1.a;
\\}
, &.{
":1:12: error: non-exhaustive enum missing integer tag type",
":1:25: note: marked non-exhaustive here",
});
case.addError(
\\const E1 = enum { a, b, c, b, d };
\\export fn foo() void {
\\ const x = E1.a;
\\}
, &.{
":1:28: error: duplicate enum tag",
":1:22: note: other tag here",
});
}
ctx.c("empty start function", linux_x64,