aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-03-17 15:26:55 -0700
committerGitHub <noreply@github.com>2024-03-17 15:26:55 -0700
commit95cb93944060d04ec49e9d2e21ef911ad2b09ccd (patch)
tree5b9839319d7d3258613a7367685c9aab1b6113f3 /src/type.zig
parentc11b6adf13fe5c765ec480af5bad6338e6982a9d (diff)
parent436c72e89a6e402b6920ab03207b95d0ca709ee9 (diff)
downloadzig-95cb93944060d04ec49e9d2e21ef911ad2b09ccd.tar.gz
zig-95cb93944060d04ec49e9d2e21ef911ad2b09ccd.zip
Merge pull request #19333 from Vexu/fixes
Miscellaneous error fixes
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/type.zig b/src/type.zig
index 9ea16d6224..8a79cb445c 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -254,7 +254,11 @@ pub const Type = struct {
.error_union_type => |error_union_type| {
try print(Type.fromInterned(error_union_type.error_set_type), writer, mod);
try writer.writeByte('!');
- try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
+ if (error_union_type.payload_type == .generic_poison_type) {
+ try writer.writeAll("anytype");
+ } else {
+ try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
+ }
return;
},
.inferred_error_set_type => |func_index| {
@@ -2833,22 +2837,40 @@ pub const Type = struct {
};
}
+ /// Asserts that the type can have a namespace.
+ pub fn getNamespaceIndex(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex {
+ return ty.getNamespace(zcu).?;
+ }
+
/// Returns null if the type has no namespace.
- pub fn getNamespaceIndex(ty: Type, mod: *Module) InternPool.OptionalNamespaceIndex {
- const ip = &mod.intern_pool;
+ pub fn getNamespace(ty: Type, zcu: *Zcu) ?InternPool.OptionalNamespaceIndex {
+ const ip = &zcu.intern_pool;
return switch (ip.indexToKey(ty.toIntern())) {
.opaque_type => ip.loadOpaqueType(ty.toIntern()).namespace,
.struct_type => ip.loadStructType(ty.toIntern()).namespace,
.union_type => ip.loadUnionType(ty.toIntern()).namespace,
.enum_type => ip.loadEnumType(ty.toIntern()).namespace,
- else => .none,
- };
- }
+ .anon_struct_type => .none,
+ .simple_type => |s| switch (s) {
+ .anyopaque,
+ .atomic_order,
+ .atomic_rmw_op,
+ .calling_convention,
+ .address_space,
+ .float_mode,
+ .reduce_op,
+ .call_modifier,
+ .prefetch_options,
+ .export_options,
+ .extern_options,
+ .type_info,
+ => .none,
+ else => null,
+ },
- /// Returns null if the type has no namespace.
- pub fn getNamespace(ty: Type, mod: *Module) ?*Module.Namespace {
- return if (getNamespaceIndex(ty, mod).unwrap()) |i| mod.namespacePtr(i) else null;
+ else => null,
+ };
}
// Works for vectors and vectors of integers.