authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 20:44:58+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 20:45:53+02:00
log6511afcfe090f26345873e7e8db3ae301f8a18a7
tree5b5284adcd5445737bef0b17021651dab6d95cb1
parent0c1d8659c51d9544fb8d5de7481e750149c262ae

Sema: fix coercion from `[:0]T` to `[*c]T`


2 files changed, 13 insertions(+), 2 deletions(-)

src/Sema.zig+3-2
......@@ -24615,8 +24615,9 @@ fn coerceExtra(
2461524615 else => break :p,
2461624616 }
2461724617 if (inst_info.size == .Slice) {
24618 if (dest_info.sentinel == null or inst_info.sentinel == null or
24619 !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type, sema.mod))
24618 assert(dest_info.sentinel == null);
24619 if (inst_info.sentinel == null or
24620 !inst_info.sentinel.?.eql(Value.zero, dest_info.pointee_type, sema.mod))
2462024621 break :p;
2462124622
2462224623 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
test/behavior/cast.zig+10
......@@ -1495,3 +1495,13 @@ test "cast typed undefined to int" {
14951495 _ = b;
14961496 }
14971497}
1498
1499test "implicit cast from [:0]T to [*c]T" {
1500 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1501
1502 var a: [:0]const u8 = "foo";
1503 var b: [*c]const u8 = a;
1504 var c = std.mem.span(b);
1505 try expect(c.len == a.len);
1506 try expect(c.ptr == a.ptr);
1507}