aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-02-17 19:54:26 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-02-18 19:17:21 -0700
commit321ccbdc525ab0f5862e42378b962c10ec54e4a1 (patch)
treec3f7ddbd4e78b3aea1905f32c6c314f1933722c2 /src/type.zig
parent5029e5364caccac07f2296c1f30f2f238f13864d (diff)
downloadzig-321ccbdc525ab0f5862e42378b962c10ec54e4a1.tar.gz
zig-321ccbdc525ab0f5862e42378b962c10ec54e4a1.zip
Sema: implement for_len
This also makes another breaking change to for loops: in order to capture a pointer of an element, one must take the address of array values. This simplifies a lot of things, and makes more sense than how it was before semantically. It is still legal to use a for loop on an array value if the corresponding element capture is byval instead of byref.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index a13e30cb4c..6226a7f2f7 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -5326,6 +5326,19 @@ pub const Type = extern union {
};
}
+ pub fn indexableHasLen(ty: Type) bool {
+ return switch (ty.zigTypeTag()) {
+ .Array, .Vector => true,
+ .Pointer => switch (ty.ptrSize()) {
+ .Many, .C => false,
+ .Slice => true,
+ .One => ty.elemType().zigTypeTag() == .Array,
+ },
+ .Struct => ty.isTuple(),
+ else => false,
+ };
+ }
+
/// Returns null if the type has no namespace.
pub fn getNamespace(self: Type) ?*Module.Namespace {
return switch (self.tag()) {