aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-23 15:58:04 +0300
committerVeikka Tuominen <git@vexu.eu>2022-09-23 17:39:06 +0300
commit581df942e1150dc2108bef1d91f0a77ba9c32e23 (patch)
tree72403a12232cffbb1635a43109c587b663e14b7e /src
parent3de5c3b5038d03759d8f5521627fdbbcad28c795 (diff)
downloadzig-581df942e1150dc2108bef1d91f0a77ba9c32e23.tar.gz
zig-581df942e1150dc2108bef1d91f0a77ba9c32e23.zip
Sema: correct sentinel check on implicit cast from array ptr
Closes #12938
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index d0ddbdbfec..022d522c35 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -23014,9 +23014,37 @@ fn coerceExtra(
const dest_is_mut = dest_info.mutable;
const dst_elem_type = dest_info.pointee_type;
- switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src)) {
+ const elem_res = try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src);
+ switch (elem_res) {
.ok => {},
- else => break :src_array_ptr,
+ else => {
+ in_memory_result = .{ .ptr_child = .{
+ .child = try elem_res.dupe(sema.arena),
+ .actual = array_elem_type,
+ .wanted = dst_elem_type,
+ } };
+ break :src_array_ptr;
+ },
+ }
+
+ if (dest_info.sentinel) |dest_sent| {
+ if (array_ty.sentinel()) |inst_sent| {
+ if (!dest_sent.eql(inst_sent, dst_elem_type, sema.mod)) {
+ in_memory_result = .{ .ptr_sentinel = .{
+ .actual = inst_sent,
+ .wanted = dest_sent,
+ .ty = dst_elem_type,
+ } };
+ break :src_array_ptr;
+ }
+ } else {
+ in_memory_result = .{ .ptr_sentinel = .{
+ .actual = Value.initTag(.unreachable_value),
+ .wanted = dest_sent,
+ .ty = dst_elem_type,
+ } };
+ break :src_array_ptr;
+ }
}
switch (dest_info.size) {
@@ -23030,17 +23058,7 @@ fn coerceExtra(
},
.Many => {
// *[N]T to [*]T
- // *[N:s]T to [*:s]T
- // *[N:s]T to [*]T
- if (dest_info.sentinel) |dst_sentinel| {
- if (array_ty.sentinel()) |src_sentinel| {
- if (src_sentinel.eql(dst_sentinel, dst_elem_type, sema.mod)) {
- return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src);
- }
- }
- } else {
- return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src);
- }
+ return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src);
},
.One => {},
}