aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-03 13:38:59 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:40:03 -0700
commite77dede87e8cff2679485aecf0d3af146595db3a (patch)
tree1e20a0b5b72790af73e56186d016749dcd92dbcf /src/Sema.zig
parent264292f430668652818b30fe6cf5d8b434530c84 (diff)
downloadzig-e77dede87e8cff2679485aecf0d3af146595db3a.tar.gz
zig-e77dede87e8cff2679485aecf0d3af146595db3a.zip
InternPool: implement typePtrOrOptionalPtrTy
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index ceaae1fbc8..c39146ca5a 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1898,10 +1898,14 @@ fn resolveMaybeUndefVal(
inst: Air.Inst.Ref,
) CompileError!?Value {
const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
- switch (val.tag()) {
- .variable => return null,
+ switch (val.ip_index) {
.generic_poison => return error.GenericPoison,
else => return val,
+ .none => switch (val.tag()) {
+ .variable => return null,
+ .generic_poison => return error.GenericPoison,
+ else => return val,
+ },
}
}
@@ -33497,6 +33501,33 @@ fn typePtrOrOptionalPtrTy(
buf: *Type.Payload.ElemType,
) !?Type {
const mod = sema.mod;
+
+ if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
+ .ptr_type => |ptr_type| switch (ptr_type.size) {
+ .Slice => return null,
+ .C => return ptr_type.elem_type.toType(),
+ .One, .Many => return ty,
+ },
+ .optional_type => |o| switch (mod.intern_pool.indexToKey(o.payload_type)) {
+ .ptr_type => |ptr_type| switch (ptr_type.size) {
+ .Slice, .C => return null,
+ .Many, .One => {
+ if (ptr_type.is_allowzero) return null;
+
+ // optionals of zero sized types behave like bools, not pointers
+ const payload_ty = o.payload_type.toType();
+ if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
+ return null;
+ }
+
+ return payload_ty;
+ },
+ },
+ else => return null,
+ },
+ else => return null,
+ };
+
switch (ty.tag()) {
.optional_single_const_pointer,
.optional_single_mut_pointer,