authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-26 00:36:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-26 00:36:24-04:00
logb4e40cb59a4d8ee498a0ae5b892bb5907745dc1e
tree52752524a9944de937e76c7d27033aad52d9516b
parentfd4c5f54f05c598c83188409afffea37d4334949
signature Commit is signed but in an unrecognized format.

fix peer type resolution with null


2 files changed, 15 insertions(+), 0 deletions(-)

src/ir.cpp+1
......@@ -10399,6 +10399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1039910399
1040010400 if (prev_type->id == ZigTypeIdNull) {
1040110401 prev_inst = cur_inst;
10402 any_are_null = true;
1040210403 continue;
1040310404 }
1040410405
test/stage1/behavior/cast.zig+14
......@@ -482,3 +482,17 @@ test "@intCast to u0 and use the result" {
482482 S.doTheTest(0, 1, 0);
483483 comptime S.doTheTest(0, 1, 0);
484484}
485
486test "peer type resolution: unreachable, null, slice" {
487 const S = struct {
488 fn doTheTest(num: usize, word: []const u8) void {
489 const result = switch (num) {
490 0 => null,
491 1 => word,
492 else => unreachable,
493 };
494 expect(mem.eql(u8, result.?, "hi"));
495 }
496 };
497 S.doTheTest(1, "hi");
498}