aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-05 23:23:05 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-05 23:26:11 -0700
commit7e9b23e6dce4d87615acd635f3731731a8601d39 (patch)
tree392b32ff570328a8fcd984013ad844b063beaa77 /src/type.zig
parentc7dc451a2a06a0ade0bb44a48cb6e5cde6e237df (diff)
downloadzig-7e9b23e6dce4d87615acd635f3731731a8601d39.tar.gz
zig-7e9b23e6dce4d87615acd635f3731731a8601d39.zip
Sema: respect requiresComptime of function return types
When doing a function call, if the return type requires comptime, the function is analyzed as an inline/comptime call. There is an important TODO here. I will reproduce the comment from this commit: > In the case of a comptime/inline function call of a generic function, > the function return type needs to be the resolved return type based on > the function parameter type expressions being evaluated with comptime arguments > passed in. Otherwise, it ends up being .generic_poison and failing the > comptime/inline function call analysis.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/type.zig b/src/type.zig
index 180fb92bf0..02b9fabe71 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -21,8 +21,14 @@ pub const Type = extern union {
tag_if_small_enough: usize,
ptr_otherwise: *Payload,
- pub fn zigTypeTag(self: Type) std.builtin.TypeId {
- switch (self.tag()) {
+ pub fn zigTypeTag(ty: Type) std.builtin.TypeId {
+ return ty.zigTypeTagOrPoison() catch unreachable;
+ }
+
+ pub fn zigTypeTagOrPoison(ty: Type) error{GenericPoison}!std.builtin.TypeId {
+ switch (ty.tag()) {
+ .generic_poison => return error.GenericPoison,
+
.u1,
.u8,
.i8,
@@ -130,7 +136,6 @@ pub const Type = extern union {
=> return .Union,
.var_args_param => unreachable, // can be any type
- .generic_poison => unreachable, // must be handled earlier
}
}
@@ -1096,6 +1101,7 @@ pub const Type = extern union {
}
/// Anything that reports hasCodeGenBits() false returns false here as well.
+ /// `generic_poison` will return false.
pub fn requiresComptime(ty: Type) bool {
return switch (ty.tag()) {
.u1,
@@ -1156,6 +1162,7 @@ pub const Type = extern union {
.error_set_single,
.error_set_inferred,
.@"opaque",
+ .generic_poison,
=> false,
.type,
@@ -1167,7 +1174,6 @@ pub const Type = extern union {
.var_args_param => unreachable,
.inferred_alloc_mut => unreachable,
.inferred_alloc_const => unreachable,
- .generic_poison => unreachable,
.array_u8,
.array_u8_sentinel_0,