| ... | @@ -12152,34 +12152,16 @@ fn fieldCallBind( | ... | @@ -12152,34 +12152,16 @@ fn fieldCallBind( |
| 12152 | const field_index = @intCast(u32, field_index_usize); | 12152 | const field_index = @intCast(u32, field_index_usize); |
| 12153 | const field = struct_obj.fields.values()[field_index]; | 12153 | const field = struct_obj.fields.values()[field_index]; |
| 12154 | | 12154 | |
| 12155 | const ptr_field_ty = try Type.ptr(arena, .{ | 12155 | return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 12156 | .pointee_type = field.ty, | | |
| 12157 | .mutable = ptr_ty.ptrIsMutable(), | | |
| 12158 | .@"addrspace" = ptr_ty.ptrAddressSpace(), | | |
| 12159 | }); | | |
| 12160 | | | |
| 12161 | if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| { | | |
| 12162 | const pointer = try sema.addConstant( | | |
| 12163 | ptr_field_ty, | | |
| 12164 | try Value.Tag.field_ptr.create(arena, .{ | | |
| 12165 | .container_ptr = struct_ptr_val, | | |
| 12166 | .field_index = field_index, | | |
| 12167 | }), | | |
| 12168 | ); | | |
| 12169 | return sema.analyzeLoad(block, src, pointer, src); | | |
| 12170 | } | | |
| 12171 | | | |
| 12172 | try sema.requireRuntimeBlock(block, src); | | |
| 12173 | const ptr_inst = try block.addStructFieldPtr(object_ptr, field_index, ptr_field_ty); | | |
| 12174 | return sema.analyzeLoad(block, src, ptr_inst, src); | | |
| 12175 | }, | 12156 | }, |
| 12176 | .Union => { | 12157 | .Union => { |
| 12177 | const union_ty = try sema.resolveTypeFields(block, src, concrete_ty); | 12158 | const union_ty = try sema.resolveTypeFields(block, src, concrete_ty); |
| 12178 | const fields = union_ty.unionFields(); | 12159 | const fields = union_ty.unionFields(); |
| 12179 | const field_index_usize = fields.getIndex(field_name) orelse break :find_field; | 12160 | const field_index_usize = fields.getIndex(field_name) orelse break :find_field; |
| | 12161 | const field_index = @intCast(u32, field_index_usize); |
| | 12162 | const field = fields.values()[field_index]; |
| 12180 | | 12163 | |
| 12181 | _ = field_index_usize; | 12164 | return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 12182 | return sema.fail(block, src, "TODO implement field calls on unions", .{}); | | |
| 12183 | }, | 12165 | }, |
| 12184 | .Type => { | 12166 | .Type => { |
| 12185 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); | 12167 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| ... | @@ -12236,6 +12218,38 @@ fn fieldCallBind( | ... | @@ -12236,6 +12218,38 @@ fn fieldCallBind( |
| 12236 | return sema.fail(block, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); | 12218 | return sema.fail(block, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); |
| 12237 | } | 12219 | } |
| 12238 | | 12220 | |
| | 12221 | fn finishFieldCallBind( |
| | 12222 | sema: *Sema, |
| | 12223 | block: *Block, |
| | 12224 | src: LazySrcLoc, |
| | 12225 | ptr_ty: Type, |
| | 12226 | field_ty: Type, |
| | 12227 | field_index: u32, |
| | 12228 | object_ptr: Air.Inst.Ref, |
| | 12229 | ) CompileError!Air.Inst.Ref { |
| | 12230 | const arena = sema.arena; |
| | 12231 | const ptr_field_ty = try Type.ptr(arena, .{ |
| | 12232 | .pointee_type = field_ty, |
| | 12233 | .mutable = ptr_ty.ptrIsMutable(), |
| | 12234 | .@"addrspace" = ptr_ty.ptrAddressSpace(), |
| | 12235 | }); |
| | 12236 | |
| | 12237 | if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| { |
| | 12238 | const pointer = try sema.addConstant( |
| | 12239 | ptr_field_ty, |
| | 12240 | try Value.Tag.field_ptr.create(arena, .{ |
| | 12241 | .container_ptr = struct_ptr_val, |
| | 12242 | .field_index = field_index, |
| | 12243 | }), |
| | 12244 | ); |
| | 12245 | return sema.analyzeLoad(block, src, pointer, src); |
| | 12246 | } |
| | 12247 | |
| | 12248 | try sema.requireRuntimeBlock(block, src); |
| | 12249 | const ptr_inst = try block.addStructFieldPtr(object_ptr, field_index, ptr_field_ty); |
| | 12250 | return sema.analyzeLoad(block, src, ptr_inst, src); |
| | 12251 | } |
| | 12252 | |
| 12239 | fn namespaceLookup( | 12253 | fn namespaceLookup( |
| 12240 | sema: *Sema, | 12254 | sema: *Sema, |
| 12241 | block: *Block, | 12255 | block: *Block, |