aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-09-24 15:19:48 -0700
committerGitHub <noreply@github.com>2023-09-24 15:19:48 -0700
commitdf5f0517b33b5f7bc2a508cf6a0ee62246f02d21 (patch)
tree64d664b74afd6d100be328b7225b87753bf62fd7 /src/type.zig
parenta9f25c7d642ec0ed047ae9be6ad87d102f3f75c8 (diff)
parent9ff872c9829c20cb16d233534248c5cf371a8bd9 (diff)
downloadzig-df5f0517b33b5f7bc2a508cf6a0ee62246f02d21.tar.gz
zig-df5f0517b33b5f7bc2a508cf6a0ee62246f02d21.zip
Merge pull request #17205 from mlugg/rls-ref
compiler: preserve result type information through address-of operator
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index 0ed8c394fc..a4f85ae946 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3182,6 +3182,17 @@ pub const Type = struct {
};
}
+ /// Traverses optional child types and error union payloads until the type
+ /// is not a pointer. For `E!?u32`, returns `u32`; for `*u8`, returns `*u8`.
+ pub fn optEuBaseType(ty: Type, mod: *Module) Type {
+ var cur = ty;
+ while (true) switch (cur.zigTypeTag(mod)) {
+ .Optional => cur = cur.optionalChild(mod),
+ .ErrorUnion => cur = cur.errorUnionPayload(mod),
+ else => return cur,
+ };
+ }
+
pub const @"u1": Type = .{ .ip_index = .u1_type };
pub const @"u8": Type = .{ .ip_index = .u8_type };
pub const @"u16": Type = .{ .ip_index = .u16_type };