Skip to content

Commit 0bce4a4

Browse files
ianprime0509andrewrk
authored andcommitted
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.
1 parent 61c588d commit 0bce4a4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Sema.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36719,7 +36719,7 @@ fn unionFields(
3671936719
if (enum_index != field_i) {
3672036720
const msg = msg: {
3672136721
const enum_field_src: LazySrcLoc = .{
36722-
.base_node_inst = tag_info.zir_index.unwrap().?,
36722+
.base_node_inst = Type.fromInterned(tag_ty).typeDeclInstAllowGeneratedTag(zcu).?,
3672336723
.offset = .{ .container_field_name = enum_index },
3672436724
};
3672536725
const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const Tag = enum { a, b };
2+
3+
const Union = union(Tag) {
4+
b,
5+
a,
6+
};
7+
8+
const BaseUnion = union(enum) {
9+
a,
10+
b,
11+
};
12+
13+
const GeneratedTagUnion = union(@typeInfo(BaseUnion).@"union".tag_type.?) {
14+
b,
15+
a,
16+
};
17+
18+
export fn entry() usize {
19+
return @sizeOf(Union) + @sizeOf(GeneratedTagUnion);
20+
}
21+
22+
// error
23+
//
24+
// :4:5: error: union field 'b' ordered differently than corresponding enum field
25+
// :1:23: note: enum field here
26+
// :14:5: error: union field 'b' ordered differently than corresponding enum field
27+
// :10:5: note: enum field here

0 commit comments

Comments
 (0)