Commit aff7b38838
Changed files (2)
src
src/ir.cpp
@@ -20884,18 +20884,19 @@ 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;
- if (type_is_invalid(end_value->value.type))
+ IrInstruction *end_value_uncasted = range->end->child;
+ if (type_is_invalid(end_value_uncasted->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"));
+ 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;
- }
BigInt start_index;
bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);
test/compile_errors.zig
@@ -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(