authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-21 14:44:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-21 14:44:24-05:00
log5b7ae86af488745fc93cdbaff11bf2438938274a
tree1848e0b2e96ea622f4a6fc8f1bb31c7721331100
parent517e8ea4269fb832f29d9eab642d57f1a8371149

fix crash when switching on enum with 1 field and no switch prongs

closes #712

2 files changed, 14 insertions(+), 1 deletions(-)

src/ir.cpp+5-1
...@@ -4992,7 +4992,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4992,7 +4992,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
49924992
4993 ir_set_cursor_at_end_and_append_block(irb, end_block);4993 ir_set_cursor_at_end_and_append_block(irb, end_block);
4994 assert(incoming_blocks.length == incoming_values.length);4994 assert(incoming_blocks.length == incoming_values.length);
4995 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);4995 if (incoming_blocks.length == 0) {
4996 return ir_build_const_void(irb, scope, node);
4997 } else {
4998 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
4999 }
4996}5000}
49975001
4998static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {5002static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) {3pub fn addCases(cases: &tests.CompileErrorContext) {
4 cases.add("switch on enum with 1 field with no prongs",
5 \\const Foo = enum { M };
6 \\
7 \\export fn entry() {
8 \\ var f = Foo.M;
9 \\ switch (f) {}
10 \\}
11 , ".tmp_source.zig:5:5: error: enumeration value 'Foo.M' not handled in switch");
12
4 cases.add("shift by negative comptime integer",13 cases.add("shift by negative comptime integer",
5 \\comptime {14 \\comptime {
6 \\ var a = 1 >> -1;15 \\ var a = 1 >> -1;