| ... | @@ -10560,18 +10560,25 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so | ... | @@ -10560,18 +10560,25 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 10560 | assert(union_field != nullptr); | 10560 | assert(union_field != nullptr); |
| 10561 | if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown))) | 10561 | if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown))) |
| 10562 | return ira->codegen->invalid_instruction; | 10562 | return ira->codegen->invalid_instruction; |
| 10563 | if (type_has_bits(union_field->type_entry)) { | 10563 | |
| 10564 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( | 10564 | switch (type_has_one_possible_value(ira->codegen, union_field->type_entry)) { |
| 10565 | union_field->enum_field->decl_index); | 10565 | case OnePossibleValueNo: |
| 10566 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 10566 | case OnePossibleValueInvalid: { |
| 10567 | buf_sprintf("cast to union '%s' must initialize '%s' field '%s'", | 10567 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 10568 | buf_ptr(&wanted_type->name), | 10568 | union_field->enum_field->decl_index); |
| 10569 | buf_ptr(&union_field->type_entry->name), | 10569 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 10570 | buf_ptr(union_field->name))); | 10570 | buf_sprintf("cast to union '%s' must initialize '%s' field '%s'", |
| 10571 | add_error_note(ira->codegen, msg, field_node, | 10571 | buf_ptr(&wanted_type->name), |
| 10572 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); | 10572 | buf_ptr(&union_field->type_entry->name), |
| 10573 | return ira->codegen->invalid_instruction; | 10573 | buf_ptr(union_field->name))); |
| | 10574 | add_error_note(ira->codegen, msg, field_node, |
| | 10575 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); |
| | 10576 | return ira->codegen->invalid_instruction; |
| | 10577 | } |
| | 10578 | case OnePossibleValueYes: |
| | 10579 | break; |
| 10574 | } | 10580 | } |
| | 10581 | |
| 10575 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); | 10582 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 10576 | result->value.special = ConstValSpecialStatic; | 10583 | result->value.special = ConstValSpecialStatic; |
| 10577 | result->value.type = wanted_type; | 10584 | result->value.type = wanted_type; |
| ... | @@ -18034,6 +18041,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr | ... | @@ -18034,6 +18041,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 18034 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | 18041 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) |
| 18035 | return err; | 18042 | return err; |
| 18036 | | 18043 | |
| | 18044 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); |
| | 18045 | if (entry != nullptr) { |
| | 18046 | *out = entry->value; |
| | 18047 | return ErrorNone; |
| | 18048 | } |
| | 18049 | |
| 18037 | ConstExprValue *result = nullptr; | 18050 | ConstExprValue *result = nullptr; |
| 18038 | switch (type_entry->id) { | 18051 | switch (type_entry->id) { |
| 18039 | case ZigTypeIdInvalid: | 18052 | case ZigTypeIdInvalid: |