aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/slice.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-15 01:04:22 +0100
committermlugg <mlugg@mlugg.co.uk>2023-06-15 01:23:52 +0100
commit45e961772050191ce94becc53dcb86971a5804ab (patch)
tree72e1bbe704eb65108f43b8b9f6a7d16d4451815d /test/behavior/slice.zig
parentb975701a4d98f2bf124fd4e66ca57e337827ec5a (diff)
downloadzig-45e961772050191ce94becc53dcb86971a5804ab.tar.gz
zig-45e961772050191ce94becc53dcb86971a5804ab.zip
Sema: don't assume slice value is interned when loading from comptime pointer
Resolves: #16030
Diffstat (limited to 'test/behavior/slice.zig')
-rw-r--r--test/behavior/slice.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig
index fb9d1e047a..79990feba4 100644
--- a/test/behavior/slice.zig
+++ b/test/behavior/slice.zig
@@ -869,3 +869,20 @@ test "write through pointer to optional slice arg" {
try S.bar(&foo);
try expectEqualStrings(foo.?, "ok");
}
+
+test "modify slice length at comptime" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const arr: [2]u8 = .{ 10, 20 };
+ comptime var s: []const u8 = arr[0..0];
+ s.len += 1;
+ const a = s;
+ s.len += 1;
+ const b = s;
+
+ try expectEqualSlices(u8, &.{10}, a);
+ try expectEqualSlices(u8, &.{ 10, 20 }, b);
+}