diff --git a/src/ir.cpp b/src/ir.cpp index c8514bf8e88d..29b6eef27ab5 100644 --- a/src/ir.cpp +++ b/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); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 57e2504e5e36..623e1e9cccb7 100644 --- a/test/compile_errors.zig +++ b/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(