| ... | @@ -14096,7 +14096,8 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I | ... | @@ -14096,7 +14096,8 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I |
| 14096 | | 14096 | |
| 14097 | // If there is only one possible tag, then we know at comptime what it is. | 14097 | // If there is only one possible tag, then we know at comptime what it is. |
| 14098 | if (enum_type->data.enumeration.layout == ContainerLayoutAuto && | 14098 | if (enum_type->data.enumeration.layout == ContainerLayoutAuto && |
| 14099 | enum_type->data.enumeration.src_field_count == 1) | 14099 | enum_type->data.enumeration.src_field_count == 1 && |
| | 14100 | !enum_type->data.enumeration.non_exhaustive) |
| 14100 | { | 14101 | { |
| 14101 | IrInstGen *result = ir_const(ira, source_instr, tag_type); | 14102 | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 14102 | init_const_bigint(result->value, tag_type, | 14103 | init_const_bigint(result->value, tag_type, |
| ... | @@ -14136,7 +14137,8 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -14136,7 +14137,8 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 14136 | | 14137 | |
| 14137 | // If there is only 1 possible tag, then we know at comptime what it is. | 14138 | // If there is only 1 possible tag, then we know at comptime what it is. |
| 14138 | if (wanted_type->data.enumeration.layout == ContainerLayoutAuto && | 14139 | if (wanted_type->data.enumeration.layout == ContainerLayoutAuto && |
| 14139 | wanted_type->data.enumeration.src_field_count == 1) | 14140 | wanted_type->data.enumeration.src_field_count == 1 && |
| | 14141 | !wanted_type->data.enumeration.non_exhaustive) // TODO are non-exhaustive union tag types supposed to be allowed? |
| 14140 | { | 14142 | { |
| 14141 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); | 14143 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 14142 | result->value->special = ConstValSpecialStatic; | 14144 | result->value->special = ConstValSpecialStatic; |
| ... | @@ -23814,7 +23816,8 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -23814,7 +23816,8 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 23814 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); | 23816 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 23815 | return result; | 23817 | return result; |
| 23816 | } | 23818 | } |
| 23817 | if (tag_type->data.enumeration.src_field_count == 1) { | 23819 | // TODO are non-exhaustive union tag types supposed to be allowed? |
| | 23820 | if (tag_type->data.enumeration.src_field_count == 1 && !tag_type->data.enumeration.non_exhaustive) { |
| 23818 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); | 23821 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 23819 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; | 23822 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 23820 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); | 23823 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| ... | @@ -23829,7 +23832,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -23829,7 +23832,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 23829 | case ZigTypeIdEnum: { | 23832 | case ZigTypeIdEnum: { |
| 23830 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) | 23833 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| 23831 | return ira->codegen->invalid_inst_gen; | 23834 | return ira->codegen->invalid_inst_gen; |
| 23832 | if (target_type->data.enumeration.src_field_count == 1) { | 23835 | if (target_type->data.enumeration.src_field_count == 1 && !target_type->data.enumeration.non_exhaustive) { |
| 23833 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; | 23836 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 23834 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); | 23837 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 23835 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); | 23838 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |