make switch expressions allow enum literal types

See #683
This commit is contained in:
Andrew Kelley 2019-03-24 01:15:21 -04:00
parent a736dfe6a1
commit aff7b38838
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 9 additions and 8 deletions

View File

@ -20884,19 +20884,20 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
IrInstruction *start_value = range->start->child;
IrInstruction *start_value_uncasted = range->start->child;
if (type_is_invalid(start_value_uncasted->value.type))
return ira->codegen->invalid_instruction;
IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
if (type_is_invalid(start_value->value.type))
return ira->codegen->invalid_instruction;
IrInstruction *end_value = range->end->child;
IrInstruction *end_value_uncasted = range->end->child;
if (type_is_invalid(end_value_uncasted->value.type))
return ira->codegen->invalid_instruction;
IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
if (type_is_invalid(end_value->value.type))
return ira->codegen->invalid_instruction;
if (start_value->value.type->id != ZigTypeIdEnum) {
ir_add_error(ira, range->start, buf_sprintf("not an enum type"));
return ira->codegen->invalid_instruction;
}
BigInt start_index;
bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);

View File

@ -203,7 +203,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const InvalidToken = struct {};
\\const ExpectedVarDeclOrFn = struct {};
,
"tmp.zig:4:9: error: not an enum type",
"tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'",
);
cases.addTest(