| ... | ... | @@ -22106,7 +22106,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil |
| 22106 | 22106 | // The fields of the union must match the enum exactly. |
| 22107 | 22107 | // Store a copy of the enum field names so we can check for |
| 22108 | 22108 | // missing or extraneous fields later. |
| 22109 | | tag_ty_field_names = try union_obj.tag_ty.enumFields().clone(decl_arena_allocator); |
| 22109 | tag_ty_field_names = try union_obj.tag_ty.enumFields().clone(sema.arena); |
| 22110 | 22110 | } |
| 22111 | 22111 | } else { |
| 22112 | 22112 | // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis |
| ... | ... | @@ -22200,20 +22200,6 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil |
| 22200 | 22200 | set.putAssumeCapacity(field_name, {}); |
| 22201 | 22201 | } |
| 22202 | 22202 | |
| 22203 | | if (tag_ty_field_names) |*names| { |
| 22204 | | const enum_has_field = names.contains(field_name); |
| 22205 | | if (!enum_has_field) { |
| 22206 | | const msg = msg: { |
| 22207 | | const msg = try sema.errMsg(block, src, "enum '{}' has no field named '{s}'", .{ union_obj.tag_ty.fmt(target), field_name }); |
| 22208 | | errdefer msg.destroy(sema.gpa); |
| 22209 | | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 22210 | | break :msg msg; |
| 22211 | | }; |
| 22212 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 22213 | | } |
| 22214 | | _ = names.orderedRemove(field_name); |
| 22215 | | } |
| 22216 | | |
| 22217 | 22203 | const field_ty: Type = if (!has_type) |
| 22218 | 22204 | Type.void |
| 22219 | 22205 | else if (field_type_ref == .none) |
| ... | ... | @@ -22245,6 +22231,19 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil |
| 22245 | 22231 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 22246 | 22232 | } |
| 22247 | 22233 | |
| 22234 | if (tag_ty_field_names) |*names| { |
| 22235 | const enum_has_field = names.orderedRemove(field_name); |
| 22236 | if (!enum_has_field) { |
| 22237 | const msg = msg: { |
| 22238 | const msg = try sema.errMsg(block, src, "enum '{}' has no field named '{s}'", .{ union_obj.tag_ty.fmt(target), field_name }); |
| 22239 | errdefer msg.destroy(sema.gpa); |
| 22240 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 22241 | break :msg msg; |
| 22242 | }; |
| 22243 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22244 | } |
| 22245 | } |
| 22246 | |
| 22248 | 22247 | gop.value_ptr.* = .{ |
| 22249 | 22248 | .ty = try field_ty.copy(decl_arena_allocator), |
| 22250 | 22249 | .abi_align = 0, |