| ... | @@ -14177,7 +14177,14 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -14177,7 +14177,14 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 14177 | if (!val) | 14177 | if (!val) |
| 14178 | return ira->codegen->invalid_inst_gen; | 14178 | return ira->codegen->invalid_inst_gen; |
| 14179 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); | 14179 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 14180 | assert(union_field != nullptr); | 14180 | if (union_field == nullptr) { |
| | 14181 | Buf *int_buf = buf_alloc(); |
| | 14182 | bigint_append_buf(int_buf, &target->value->data.x_enum_tag, 10); |
| | 14183 | |
| | 14184 | ir_add_error(ira, &target->base, |
| | 14185 | buf_sprintf("no tag by value %s", buf_ptr(int_buf))); |
| | 14186 | return ira->codegen->invalid_inst_gen; |
| | 14187 | } |
| 14181 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); | 14188 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); |
| 14182 | if (field_type == nullptr) | 14189 | if (field_type == nullptr) |
| 14183 | return ira->codegen->invalid_inst_gen; | 14190 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -14213,6 +14220,13 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -14213,6 +14220,13 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 14213 | return result; | 14220 | return result; |
| 14214 | } | 14221 | } |
| 14215 | | 14222 | |
| | 14223 | if (target->value->type->data.enumeration.non_exhaustive) { |
| | 14224 | ir_add_error(ira, source_instr, |
| | 14225 | buf_sprintf("runtime cast to union '%s' from non-exhustive enum", |
| | 14226 | buf_ptr(&wanted_type->name))); |
| | 14227 | return ira->codegen->invalid_inst_gen; |
| | 14228 | } |
| | 14229 | |
| 14216 | // if the union has all fields 0 bits, we can do it | 14230 | // if the union has all fields 0 bits, we can do it |
| 14217 | // and in fact it's a noop cast because the union value is just the enum value | 14231 | // and in fact it's a noop cast because the union value is just the enum value |
| 14218 | if (wanted_type->data.unionation.gen_field_count == 0) { | 14232 | if (wanted_type->data.unionation.gen_field_count == 0) { |