Skip to content

Commit b4e40cb

Browse files
committed
fix peer type resolution with null
1 parent fd4c5f5 commit b4e40cb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ir.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
486+
test "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+
}

0 commit comments

Comments
 (0)