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
signaturelock-open 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...@@ -10399,6 +10399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1039910399
10400 if (prev_type->id == ZigTypeIdNull) {10400 if (prev_type->id == ZigTypeIdNull) {
10401 prev_inst = cur_inst;10401 prev_inst = cur_inst;
10402 any_are_null = true;
10402 continue;10403 continue;
10403 }10404 }
1040410405
test/stage1/behavior/cast.zig+14
...@@ -482,3 +482,17 @@ test "@intCast to u0 and use the result" {...@@ -482,3 +482,17 @@ test "@intCast to u0 and use the result" {
482 S.doTheTest(0, 1, 0);482 S.doTheTest(0, 1, 0);
483 comptime S.doTheTest(0, 1, 0);483 comptime S.doTheTest(0, 1, 0);
484}484}
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}