aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-07 15:41:52 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-07 15:46:53 -0700
commitf81b2531cb4904064446f84a06f6e09e4120e28a (patch)
treee4bac7a1a13c56b728309086d983091e9e009a65 /src/type.zig
parentade85471e2cdab466ba685a38c2c7949c9dd1632 (diff)
downloadzig-f81b2531cb4904064446f84a06f6e09e4120e28a.tar.gz
zig-f81b2531cb4904064446f84a06f6e09e4120e28a.zip
stage2: pass some pointer tests
* New AIR instructions: ptr_add, ptr_sub, ptr_elem_val, ptr_ptr_elem_val - See the doc comments for details. * Sema: implement runtime pointer arithmetic. * Sema: implement elem_val for many-pointers. * Sema: support coercion from `*[N:s]T` to `[*]T`. * Type: isIndexable handles many-pointers.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/type.zig b/src/type.zig
index 02b9fabe71..28b87a8afe 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -2753,11 +2753,15 @@ pub const Type = extern union {
};
}
- pub fn isIndexable(self: Type) bool {
- const zig_tag = self.zigTypeTag();
- // TODO tuples are indexable
- return zig_tag == .Array or zig_tag == .Vector or self.isSlice() or
- (self.isSinglePointer() and self.elemType().zigTypeTag() == .Array);
+ pub fn isIndexable(ty: Type) bool {
+ return switch (ty.zigTypeTag()) {
+ .Array, .Vector => true,
+ .Pointer => switch (ty.ptrSize()) {
+ .Slice, .Many, .C => true,
+ .One => ty.elemType().zigTypeTag() == .Array,
+ },
+ else => false, // TODO tuples are indexable
+ };
}
/// Returns null if the type has no namespace.