authorgravatar for isaachier@gmail.comIsaac Hier <isaachier@gmail.com> 2018-07-04 13:27:10-04:00
committergravatar for isaachier@gmail.comIsaac Hier <isaachier@gmail.com> 2018-07-04 13:27:10-04:00
log9cff23dbf9ff3da716a1c4397f9411eba09f6cac
treeebde3411341a755db5a13b13b9324dd99e8e0a51
parent9395162a7c41689bcd1c0c48f9eabffc1485fc74

Fix assertion crash on enum switch values


4 files changed, 24 insertions(+), 13 deletions(-)

src/ir.cpp+6-1
......@@ -19149,9 +19149,14 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1914919149 if (!end_val)
1915019150 return ira->codegen->builtin_types.entry_invalid;
1915119151
19152 printf("%s\n", buf_ptr(&start_val->type->name));
19152 if (start_val->type->id == TypeTableEntryIdEnum)
19153 return ira->codegen->builtin_types.entry_invalid;
1915319154 assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);
19155
19156 if (end_val->type->id == TypeTableEntryIdEnum)
19157 return ira->codegen->builtin_types.entry_invalid;
1915419158 assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);
19159
1915519160 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
1915619161 start_value->source_node);
1915719162 if (prev_node != nullptr) {
test/behavior.zig-1
......@@ -52,7 +52,6 @@ comptime {
5252 _ = @import("cases/switch.zig");
5353 _ = @import("cases/switch_prong_err_enum.zig");
5454 _ = @import("cases/switch_prong_implicit_cast.zig");
55 _ = @import("cases/switch_usize_enum_prongs.zig");
5655 _ = @import("cases/syntax.zig");
5756 _ = @import("cases/this.zig");
5857 _ = @import("cases/try.zig");
test/cases/switch_usize_enum_prongs.zig deleted-11
......@@ -1,11 +0,0 @@
1const E = enum(usize) { One, Two };
2
3test "aoeou" {
4 foo(1);
5}
6
7fn foo(x: usize) void {
8 switch (x) {
9 E.One => {},
10 }
11}
test/compile_errors.zig+18
......@@ -358,6 +358,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
358358 ".tmp_source.zig:3:14: note: other value is here",
359359 );
360360
361
362 cases.add(
363 "invalid cast from integral type to enum",
364 \\const E = enum(usize) { One, Two };
365 \\
366 \\export fn entry() void {
367 \\ foo(1);
368 \\}
369 \\
370 \\fn foo(x: usize) void {
371 \\ switch (x) {
372 \\ E.One => {},
373 \\ }
374 \\}
375 ,
376 ".tmp_source.zig:9:10: error: expected type 'usize', found 'E'"
377 );
378
361379 cases.add(
362380 "range operator in switch used on error set",
363381 \\export fn entry() void {