diff options
| author | Veikka Tuominen <git@vexu.eu> | 2024-03-17 13:23:54 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2024-03-17 14:42:12 +0200 |
| commit | fec4b7ef5c6a9fc2da1708be6e5be0a619d4b948 (patch) | |
| tree | 0597cfbca81a6370617fcefb6833d2a4c9afe967 /src/type.zig | |
| parent | f983adfc1076adc8509458c4bb64102c797041ff (diff) | |
| download | zig-fec4b7ef5c6a9fc2da1708be6e5be0a619d4b948.tar.gz zig-fec4b7ef5c6a9fc2da1708be6e5be0a619d4b948.zip | |
Sema: fix spurious type has no namespace error
Closes #19232
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/type.zig b/src/type.zig index b0da997de1..8c2fd4e733 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2845,22 +2845,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. |
