Sema: handle generated tag enums in union field order check

Fixes #23059

The "note: enum field here" now references the field in the base union type rather than crashing.
This commit is contained in:
Ian Johnson 2025-03-03 21:57:52 -05:00 committed by Andrew Kelley
parent 61c588d726
commit 0bce4a4e05
2 changed files with 28 additions and 1 deletions

View file

@ -36719,7 +36719,7 @@ fn unionFields(
if (enum_index != field_i) {
const msg = msg: {
const enum_field_src: LazySrcLoc = .{
.base_node_inst = tag_info.zir_index.unwrap().?,
.base_node_inst = Type.fromInterned(tag_ty).typeDeclInstAllowGeneratedTag(zcu).?,
.offset = .{ .container_field_name = enum_index },
};
const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{

View file

@ -0,0 +1,27 @@
const Tag = enum { a, b };
const Union = union(Tag) {
b,
a,
};
const BaseUnion = union(enum) {
a,
b,
};
const GeneratedTagUnion = union(@typeInfo(BaseUnion).@"union".tag_type.?) {
b,
a,
};
export fn entry() usize {
return @sizeOf(Union) + @sizeOf(GeneratedTagUnion);
}
// error
//
// :4:5: error: union field 'b' ordered differently than corresponding enum field
// :1:23: note: enum field here
// :14:5: error: union field 'b' ordered differently than corresponding enum field
// :10:5: note: enum field here