From 6511afcfe090f26345873e7e8db3ae301f8a18a7 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 19 Dec 2022 20:44:58 +0200 Subject: [PATCH] Sema: fix coercion from `[:0]T` to `[*c]T` --- src/Sema.zig | 5 +++-- test/behavior/cast.zig | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index f03211210c..f068018ddb 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -24615,8 +24615,9 @@ fn coerceExtra( else => break :p, } if (inst_info.size == .Slice) { - if (dest_info.sentinel == null or inst_info.sentinel == null or - !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type, sema.mod)) + assert(dest_info.sentinel == null); + if (inst_info.sentinel == null or + !inst_info.sentinel.?.eql(Value.zero, dest_info.pointee_type, sema.mod)) break :p; const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty); diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 1822922ec2..0b276deba7 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -1495,3 +1495,13 @@ test "cast typed undefined to int" { _ = b; } } + +test "implicit cast from [:0]T to [*c]T" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + + var a: [:0]const u8 = "foo"; + var b: [*c]const u8 = a; + var c = std.mem.span(b); + try expect(c.len == a.len); + try expect(c.ptr == a.ptr); +}