| ... | @@ -21933,6 +21933,7 @@ fn unionFieldPtr( | ... | @@ -21933,6 +21933,7 @@ fn unionFieldPtr( |
| 21933 | .mutable = union_ptr_ty.ptrIsMutable(), | 21933 | .mutable = union_ptr_ty.ptrIsMutable(), |
| 21934 | .@"addrspace" = union_ptr_ty.ptrAddressSpace(), | 21934 | .@"addrspace" = union_ptr_ty.ptrAddressSpace(), |
| 21935 | }); | 21935 | }); |
| | 21936 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?); |
| 21936 | | 21937 | |
| 21937 | if (initializing and field.ty.zigTypeTag() == .NoReturn) { | 21938 | if (initializing and field.ty.zigTypeTag() == .NoReturn) { |
| 21938 | const msg = msg: { | 21939 | const msg = msg: { |
| ... | @@ -21954,11 +21955,10 @@ fn unionFieldPtr( | ... | @@ -21954,11 +21955,10 @@ fn unionFieldPtr( |
| 21954 | if (union_val.isUndef()) { | 21955 | if (union_val.isUndef()) { |
| 21955 | return sema.failWithUseOfUndef(block, src); | 21956 | return sema.failWithUseOfUndef(block, src); |
| 21956 | } | 21957 | } |
| 21957 | const enum_field_index = union_obj.tag_ty.enumFieldIndex(field_name).?; | | |
| 21958 | const tag_and_val = union_val.castTag(.@"union").?.data; | 21958 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| 21959 | var field_tag_buf: Value.Payload.U32 = .{ | 21959 | var field_tag_buf: Value.Payload.U32 = .{ |
| 21960 | .base = .{ .tag = .enum_field_index }, | 21960 | .base = .{ .tag = .enum_field_index }, |
| 21961 | .data = @intCast(u32, enum_field_index), | 21961 | .data = enum_field_index, |
| 21962 | }; | 21962 | }; |
| 21963 | const field_tag = Value.initPayload(&field_tag_buf.base); | 21963 | const field_tag = Value.initPayload(&field_tag_buf.base); |
| 21964 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); | 21964 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); |
| ... | @@ -21990,7 +21990,7 @@ fn unionFieldPtr( | ... | @@ -21990,7 +21990,7 @@ fn unionFieldPtr( |
| 21990 | if (!initializing and union_obj.layout == .Auto and block.wantSafety() and | 21990 | if (!initializing and union_obj.layout == .Auto and block.wantSafety() and |
| 21991 | union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1) | 21991 | union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1) |
| 21992 | { | 21992 | { |
| 21993 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index); | 21993 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| 21994 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 21994 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); |
| 21995 | // TODO would it be better if get_union_tag supported pointers to unions? | 21995 | // TODO would it be better if get_union_tag supported pointers to unions? |
| 21996 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); | 21996 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); |
| ... | @@ -22020,15 +22020,15 @@ fn unionFieldVal( | ... | @@ -22020,15 +22020,15 @@ fn unionFieldVal( |
| 22020 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 22020 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 22021 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); | 22021 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 22022 | const field = union_obj.fields.values()[field_index]; | 22022 | const field = union_obj.fields.values()[field_index]; |
| | 22023 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?); |
| 22023 | | 22024 | |
| 22024 | if (try sema.resolveMaybeUndefVal(block, src, union_byval)) |union_val| { | 22025 | if (try sema.resolveMaybeUndefVal(block, src, union_byval)) |union_val| { |
| 22025 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); | 22026 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); |
| 22026 | | 22027 | |
| 22027 | const tag_and_val = union_val.castTag(.@"union").?.data; | 22028 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| 22028 | const enum_field_index = union_obj.tag_ty.enumFieldIndex(field_name).?; | | |
| 22029 | var field_tag_buf: Value.Payload.U32 = .{ | 22029 | var field_tag_buf: Value.Payload.U32 = .{ |
| 22030 | .base = .{ .tag = .enum_field_index }, | 22030 | .base = .{ .tag = .enum_field_index }, |
| 22031 | .data = @intCast(u32, enum_field_index), | 22031 | .data = enum_field_index, |
| 22032 | }; | 22032 | }; |
| 22033 | const field_tag = Value.initPayload(&field_tag_buf.base); | 22033 | const field_tag = Value.initPayload(&field_tag_buf.base); |
| 22034 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); | 22034 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); |
| ... | @@ -22064,7 +22064,7 @@ fn unionFieldVal( | ... | @@ -22064,7 +22064,7 @@ fn unionFieldVal( |
| 22064 | if (union_obj.layout == .Auto and block.wantSafety() and | 22064 | if (union_obj.layout == .Auto and block.wantSafety() and |
| 22065 | union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1) | 22065 | union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1) |
| 22066 | { | 22066 | { |
| 22067 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index); | 22067 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| 22068 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 22068 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); |
| 22069 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); | 22069 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); |
| 22070 | const ok = try block.addBinOp(.cmp_eq, active_tag, wanted_tag); | 22070 | const ok = try block.addBinOp(.cmp_eq, active_tag, wanted_tag); |