authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-09 13:18:13-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-09 13:18:13-04:00
logc459edac18a53854dbfdebe50a370d169e715145
tree75ec87c03ff82d59503657d9d291cb88b7638429
parent72899da44bb95ebd90f5fcc5b0d3212491f94e9a
signaturelock-open Commit is signed but in an unrecognized format.

compile error for attempt to cast enum literal to error

closes #2203

2 files changed, 19 insertions(+), 2 deletions(-)

src/ir.cpp+8-2
......@@ -21213,11 +21213,17 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2121321213 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
2121421214 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2121521215
21216 IrInstruction *start_value = range->start->child;
21216 IrInstruction *start_value_uncasted = range->start->child;
21217 if (type_is_invalid(start_value_uncasted->value.type))
21218 return ira->codegen->invalid_instruction;
21219 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
2121721220 if (type_is_invalid(start_value->value.type))
2121821221 return ira->codegen->invalid_instruction;
2121921222
21220 IrInstruction *end_value = range->end->child;
21223 IrInstruction *end_value_uncasted = range->end->child;
21224 if (type_is_invalid(end_value_uncasted->value.type))
21225 return ira->codegen->invalid_instruction;
21226 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
2122121227 if (type_is_invalid(end_value->value.type))
2122221228 return ira->codegen->invalid_instruction;
2122321229
test/compile_errors.zig+11
......@@ -2,6 +2,17 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "attempt to cast enum literal to error",
7 \\export fn entry() void {
8 \\ switch (error.Hi) {
9 \\ .Hi => {},
10 \\ }
11 \\}
12 ,
13 "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'",
14 );
15
516 cases.add(
617 "@sizeOf bad type",
718 \\export fn entry() void {