aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorCarl Ã…stholm <carl@astholm.se>2024-02-13 22:30:14 +0100
committerAndrew Kelley <andrew@ziglang.org>2024-04-07 15:10:49 -0700
commit278db0ad4543d7a768c63c5482b8873b58690920 (patch)
tree74dae2e3443bc7018ff2878f08a1c6e475931cfe /src/Sema.zig
parentfdd6c31e8b25f9eed81c1e78fa71eca17fd29f68 (diff)
downloadzig-278db0ad4543d7a768c63c5482b8873b58690920.tar.gz
zig-278db0ad4543d7a768c63c5482b8873b58690920.zip
Sema: support coercing ref to anonymous array init to many-pointer
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 39d687c18a..3635d39b98 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -4557,14 +4557,20 @@ fn zirValidateArrayInitRefTy(
};
const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);
assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
- if (ptr_ty.isSlice(mod)) {
- // Use array of correct length
- const arr_ty = try mod.arrayType(.{
- .len = extra.elem_count,
- .child = ptr_ty.childType(mod).toIntern(),
- .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
- });
- return Air.internedToRef(arr_ty.toIntern());
+ switch (mod.intern_pool.indexToKey(ptr_ty.toIntern())) {
+ .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
+ .Slice, .Many => {
+ // Use array of correct length
+ const arr_ty = try mod.arrayType(.{
+ .len = extra.elem_count,
+ .child = ptr_ty.childType(mod).toIntern(),
+ .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
+ });
+ return Air.internedToRef(arr_ty.toIntern());
+ },
+ else => {},
+ },
+ else => {},
}
// Otherwise, we just want the pointer child type
const ret_ty = ptr_ty.childType(mod);