compile error for attempt to cast enum literal to error

closes #2203
master
Andrew Kelley 2019-05-09 13:18:13 -04:00
parent 72899da44b
commit c459edac18
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 19 additions and 2 deletions

View File

@ -21213,11 +21213,17 @@ 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;

View File

@ -2,6 +2,17 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"attempt to cast enum literal to error",
\\export fn entry() void {
\\ switch (error.Hi) {
\\ .Hi => {},
\\ }
\\}
,
"tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'",
);
cases.add(
"@sizeOf bad type",
\\export fn entry() void {