| author | |
| committer | |
| log | 2ef72f84ca3cc74b24c3a89e52c72dce66e31638 |
| tree | 432c5b343932de5d101e32c9abb6a15d4d459e16 |
| parent | 8b9c51751541a405b1035a6bc5a982f51e642d35 |
Fixes #23059
The "note: enum field here" now references the field in the base union type rather than crashing.2 files changed, 28 insertions(+), 1 deletions(-)
src/Sema.zig+1-1| ... | ... | @@ -36719,7 +36719,7 @@ fn unionFields( |
| 36719 | 36719 | if (enum_index != field_i) { |
| 36720 | 36720 | const msg = msg: { |
| 36721 | 36721 | const enum_field_src: LazySrcLoc = .{ |
| 36722 | .base_node_inst = tag_info.zir_index.unwrap().?, | |
| 36722 | .base_node_inst = Type.fromInterned(tag_ty).typeDeclInstAllowGeneratedTag(zcu).?, | |
| 36723 | 36723 | .offset = .{ .container_field_name = enum_index }, |
| 36724 | 36724 | }; |
| 36725 | 36725 | const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{ |
test/cases/compile_errors/union_field_ordered_differently_than_enum.zig created+27| ... | ... | @@ -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 |