aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-13 16:31:07 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-13 16:31:07 -0700
commitda7fcfd1586fa93c3d00815f60030e00ea583701 (patch)
treed1f9b47a50df7ebff0b43a5ca98a406149821ddf /test
parente851d89113a57064c38ed85722edc7f686d0c11a (diff)
downloadzig-da7fcfd1586fa93c3d00815f60030e00ea583701.tar.gz
zig-da7fcfd1586fa93c3d00815f60030e00ea583701.zip
stage2: implement Sema for elemVal for comptime slice
Diffstat (limited to 'test')
-rw-r--r--test/behavior/slice.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig
index 168754381a..5dc652d678 100644
--- a/test/behavior/slice.zig
+++ b/test/behavior/slice.zig
@@ -3,3 +3,24 @@ const expect = std.testing.expect;
const expectEqualSlices = std.testing.expectEqualSlices;
const expectEqual = std.testing.expectEqual;
const mem = std.mem;
+
+// comptime array passed as slice argument
+comptime {
+ const S = struct {
+ fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) ?usize {
+ var i: usize = start_index;
+ while (i < slice.len) : (i += 1) {
+ if (slice[i] == value) return i;
+ }
+ return null;
+ }
+
+ fn indexOfScalar(comptime T: type, slice: []const T, value: T) ?usize {
+ return indexOfScalarPos(T, slice, 0, value);
+ }
+ };
+ const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
+ const list: []const type = &unsigned;
+ var pos = S.indexOfScalar(type, list, c_ulong).?;
+ if (pos != 1) @compileError("bad pos");
+}