| ... | @@ -19128,10 +19128,6 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru | ... | @@ -19128,10 +19128,6 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 19128 | assert(enum_type != nullptr); | 19128 | assert(enum_type != nullptr); |
| 19129 | assert(enum_type->id == ZigTypeIdEnum); | 19129 | assert(enum_type->id == ZigTypeIdEnum); |
| 19130 | | 19130 | |
| 19131 | if (instruction->prongs_len != 1) { | | |
| 19132 | return target_value_ptr; | | |
| 19133 | } | | |
| 19134 | | | |
| 19135 | IrInstruction *prong_value = instruction->prongs_ptr[0]->child; | 19131 | IrInstruction *prong_value = instruction->prongs_ptr[0]->child; |
| 19136 | if (type_is_invalid(prong_value->value.type)) | 19132 | if (type_is_invalid(prong_value->value.type)) |
| 19137 | return ira->codegen->invalid_instruction; | 19133 | return ira->codegen->invalid_instruction; |
| ... | @@ -19146,6 +19142,40 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru | ... | @@ -19146,6 +19142,40 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 19146 | | 19142 | |
| 19147 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); | 19143 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); |
| 19148 | | 19144 | |
| | 19145 | if (instruction->prongs_len != 1) { |
| | 19146 | ErrorMsg *invalid_payload = nullptr; |
| | 19147 | Buf *invalid_payload_list = nullptr; |
| | 19148 | |
| | 19149 | for (size_t i = 1; i < instruction->prongs_len; i++) { |
| | 19150 | IrInstruction *casted_prong_value = ir_implicit_cast(ira, instruction->prongs_ptr[i]->child, enum_type); |
| | 19151 | if (type_is_invalid(casted_prong_value->value.type)) |
| | 19152 | return ira->codegen->invalid_instruction; |
| | 19153 | |
| | 19154 | ConstExprValue *next_prong = ir_resolve_const(ira, casted_prong_value, UndefBad); |
| | 19155 | if (!next_prong) |
| | 19156 | return ira->codegen->invalid_instruction; |
| | 19157 | |
| | 19158 | ZigType *payload = find_union_field_by_tag(target_type, &next_prong->data.x_enum_tag)->type_entry; |
| | 19159 | |
| | 19160 | if (field->type_entry != payload) { |
| | 19161 | if (!invalid_payload) { |
| | 19162 | invalid_payload = ir_add_error(ira, &instruction->base, |
| | 19163 | buf_sprintf("switch prong contains cases with differing payloads")); |
| | 19164 | invalid_payload_list = buf_sprintf("types %s", buf_ptr(&field->type_entry->name)); |
| | 19165 | } |
| | 19166 | |
| | 19167 | if (i == instruction->prongs_len - 1) |
| | 19168 | buf_append_buf(invalid_payload_list, buf_sprintf(" and %s", buf_ptr(&payload->name))); |
| | 19169 | else |
| | 19170 | buf_append_buf(invalid_payload_list, buf_sprintf(", %s", buf_ptr(&payload->name))); |
| | 19171 | } |
| | 19172 | } |
| | 19173 | |
| | 19174 | if (invalid_payload) |
| | 19175 | add_error_note(ira->codegen, invalid_payload, |
| | 19176 | ((IrInstruction*)instruction)->source_node, invalid_payload_list); |
| | 19177 | } |
| | 19178 | |
| 19149 | if (instr_is_comptime(target_value_ptr)) { | 19179 | if (instr_is_comptime(target_value_ptr)) { |
| 19150 | ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); | 19180 | ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 19151 | if (!target_value_ptr) | 19181 | if (!target_value_ptr) |