| ... | @@ -8778,13 +8778,20 @@ fn structFieldPtr( | ... | @@ -8778,13 +8778,20 @@ fn structFieldPtr( |
| 8778 | const arena = sema.arena; | 8778 | const arena = sema.arena; |
| 8779 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); | 8779 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); |
| 8780 | | 8780 | |
| | 8781 | const struct_ptr_ty = sema.typeOf(struct_ptr); |
| 8781 | const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty); | 8782 | const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty); |
| 8782 | const struct_obj = struct_ty.castTag(.@"struct").?.data; | 8783 | const struct_obj = struct_ty.castTag(.@"struct").?.data; |
| 8783 | | 8784 | |
| 8784 | const field_index = struct_obj.fields.getIndex(field_name) orelse | 8785 | const field_index = struct_obj.fields.getIndex(field_name) orelse |
| 8785 | return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name); | 8786 | return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name); |
| 8786 | const field = struct_obj.fields.values()[field_index]; | 8787 | const field = struct_obj.fields.values()[field_index]; |
| 8787 | const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One); | 8788 | const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace( |
| | 8789 | arena, |
| | 8790 | field.ty, |
| | 8791 | struct_ptr_ty.ptrIsMutable(), |
| | 8792 | .One, |
| | 8793 | struct_ptr_ty.ptrAddressSpace(), |
| | 8794 | ); |
| 8788 | | 8795 | |
| 8789 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { | 8796 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { |
| 8790 | return sema.addConstant( | 8797 | return sema.addConstant( |
| ... | @@ -8875,6 +8882,7 @@ fn unionFieldPtr( | ... | @@ -8875,6 +8882,7 @@ fn unionFieldPtr( |
| 8875 | const arena = sema.arena; | 8882 | const arena = sema.arena; |
| 8876 | assert(unresolved_union_ty.zigTypeTag() == .Union); | 8883 | assert(unresolved_union_ty.zigTypeTag() == .Union); |
| 8877 | | 8884 | |
| | 8885 | const union_ptr_ty = sema.typeOf(union_ptr); |
| 8878 | const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty); | 8886 | const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty); |
| 8879 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 8887 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 8880 | | 8888 | |
| ... | @@ -8882,7 +8890,13 @@ fn unionFieldPtr( | ... | @@ -8882,7 +8890,13 @@ fn unionFieldPtr( |
| 8882 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name); | 8890 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name); |
| 8883 | | 8891 | |
| 8884 | const field = union_obj.fields.values()[field_index]; | 8892 | const field = union_obj.fields.values()[field_index]; |
| 8885 | const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One); | 8893 | const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace( |
| | 8894 | arena, |
| | 8895 | field.ty, |
| | 8896 | union_ptr_ty.ptrIsMutable(), |
| | 8897 | .One, |
| | 8898 | union_ptr_ty.ptrAddressSpace(), |
| | 8899 | ); |
| 8886 | | 8900 | |
| 8887 | if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| { | 8901 | if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| { |
| 8888 | // TODO detect inactive union field and emit compile error | 8902 | // TODO detect inactive union field and emit compile error |