| ... | ... | @@ -6938,7 +6938,6 @@ fn zirSwitchCapture( |
| 6938 | 6938 | const switch_info = zir_datas[capture_info.switch_inst].pl_node; |
| 6939 | 6939 | const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index); |
| 6940 | 6940 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node }; |
| 6941 | | const switch_src = switch_info.src(); |
| 6942 | 6941 | const operand_is_ref = switch_extra.data.bits.is_ref; |
| 6943 | 6942 | const cond_inst = Zir.refToIndex(switch_extra.data.operand).?; |
| 6944 | 6943 | const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node; |
| ... | ... | @@ -6965,7 +6964,29 @@ fn zirSwitchCapture( |
| 6965 | 6964 | } |
| 6966 | 6965 | |
| 6967 | 6966 | if (is_multi) { |
| 6968 | | return sema.fail(block, switch_src, "TODO implement Sema for switch capture multi", .{}); |
| 6967 | const items = switch_extra.data.getMultiProng(sema.code, switch_extra.end, capture_info.prong_index).items; |
| 6968 | |
| 6969 | var names: Module.ErrorSet.NameMap = .{}; |
| 6970 | try names.ensureUnusedCapacity(sema.arena, items.len); |
| 6971 | for (items) |item| { |
| 6972 | const item_ref = sema.resolveInst(item); |
| 6973 | // Previous switch validation ensured this will succeed |
| 6974 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable; |
| 6975 | names.putAssumeCapacityNoClobber( |
| 6976 | item_val.getError().?, |
| 6977 | {}, |
| 6978 | ); |
| 6979 | } |
| 6980 | |
| 6981 | // names must be sorted |
| 6982 | Module.ErrorSet.sortNames(&names); |
| 6983 | const else_error_ty = try Type.Tag.error_set_merged.create(sema.arena, names); |
| 6984 | |
| 6985 | const operand = if (operand_is_ref) |
| 6986 | try sema.analyzeLoad(block, operand_src, operand_ptr, operand_src) |
| 6987 | else |
| 6988 | operand_ptr; |
| 6989 | return sema.bitCast(block, else_error_ty, operand, operand_src); |
| 6969 | 6990 | } |
| 6970 | 6991 | const scalar_prong = switch_extra.data.getScalarProng(sema.code, switch_extra.end, capture_info.prong_index); |
| 6971 | 6992 | const item = sema.resolveInst(scalar_prong.item); |
| ... | ... | @@ -7022,7 +7043,12 @@ fn zirSwitchCapture( |
| 7022 | 7043 | return block.addStructFieldVal(operand, field_index, field.ty); |
| 7023 | 7044 | }, |
| 7024 | 7045 | .ErrorSet => { |
| 7025 | | return sema.fail(block, operand_src, "TODO implement Sema for zirSwitchCapture for error sets", .{}); |
| 7046 | const item_ty = try Type.Tag.error_set_single.create(sema.arena, item_val.getError().?); |
| 7047 | const operand = if (operand_is_ref) |
| 7048 | try sema.analyzeLoad(block, operand_src, operand_ptr, operand_src) |
| 7049 | else |
| 7050 | operand_ptr; |
| 7051 | return sema.bitCast(block, item_ty, operand, operand_src); |
| 7026 | 7052 | }, |
| 7027 | 7053 | else => { |
| 7028 | 7054 | return sema.fail(block, operand_src, "switch on type '{}' provides no capture value", .{ |