| ... | @@ -20310,11 +20310,41 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is | ... | @@ -20310,11 +20310,41 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 20310 | const zcu = pt.zcu; | 20310 | const zcu = pt.zcu; |
| 20311 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 20311 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20312 | const src = block.nodeOffset(inst_data.src_node); | 20312 | const src = block.nodeOffset(inst_data.src_node); |
| | 20313 | |
| 20313 | // Generic poison means this is an untyped anonymous empty struct/array init | 20314 | // Generic poison means this is an untyped anonymous empty struct/array init |
| 20314 | const ty_operand = try sema.resolveTypeOrPoison(block, src, inst_data.operand) orelse return .empty_tuple; | 20315 | const ty_operand = try sema.resolveTypeOrPoison(block, src, inst_data.operand) orelse { |
| | 20316 | if (is_byref) { |
| | 20317 | return sema.uavRef(.empty_tuple); |
| | 20318 | } else { |
| | 20319 | return .empty_tuple; |
| | 20320 | } |
| | 20321 | }; |
| | 20322 | |
| 20315 | const init_ty = if (is_byref) ty: { | 20323 | const init_ty = if (is_byref) ty: { |
| 20316 | const ptr_ty = ty_operand.optEuBaseType(zcu); | 20324 | const ptr_ty = ty_operand.optEuBaseType(zcu); |
| 20317 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction | 20325 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| | 20326 | switch (ptr_ty.ptrSize(zcu)) { |
| | 20327 | // Use a zero-length array for a slice or many-ptr result |
| | 20328 | .slice, .many => break :ty try pt.arrayType(.{ |
| | 20329 | .len = 0, |
| | 20330 | .child = ptr_ty.childType(zcu).toIntern(), |
| | 20331 | .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none, |
| | 20332 | }), |
| | 20333 | // Just use the child type for a single-pointer or C-pointer result |
| | 20334 | .one, .c => { |
| | 20335 | const child = ptr_ty.childType(zcu); |
| | 20336 | if (child.toIntern() == .anyopaque_type) { |
| | 20337 | // ...unless that child is anyopaque, in which case this is equivalent to an untyped init. |
| | 20338 | // `.{}` is an empty tuple. |
| | 20339 | if (is_byref) { |
| | 20340 | return sema.uavRef(.empty_tuple); |
| | 20341 | } else { |
| | 20342 | return .empty_tuple; |
| | 20343 | } |
| | 20344 | } |
| | 20345 | break :ty child; |
| | 20346 | }, |
| | 20347 | } |
| 20318 | if (!ptr_ty.isSlice(zcu)) { | 20348 | if (!ptr_ty.isSlice(zcu)) { |
| 20319 | break :ty ptr_ty.childType(zcu); | 20349 | break :ty ptr_ty.childType(zcu); |
| 20320 | } | 20350 | } |