aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-23 09:40:29 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-23 17:08:08 -0400
commita36f4ee290fa9f3f1515e8aa9bd2bb0f0117c505 (patch)
tree48684ef68021b319f9ed9844c5222e998a21b9e5 /test/compile_errors.zig
parentf27d3409bdbe4a2b1b59f0b7336e582488e35986 (diff)
downloadzig-a36f4ee290fa9f3f1515e8aa9bd2bb0f0117c505.tar.gz
zig-a36f4ee290fa9f3f1515e8aa9bd2bb0f0117c505.zip
stage2: able to slice to sentinel index at comptime
The runtime behavior allowed this in both stage1 and stage2, but stage1 fails with index out of bounds during comptime. This behavior makes sense to support, and comptime behavior should match runtime behavior. I implement this fix only in stage2.
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index c479dd9c88..5008bdd7b8 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -26,11 +26,16 @@ pub fn addCases(ctx: *TestContext) !void {
\\comptime {
\\ var array = [_:0]u8{ 1, 2, 3, 4 };
\\ var src_slice: [:0]u8 = &array;
- \\ var slice = src_slice[2..5];
+ \\ var slice = src_slice[2..6];
\\ _ = slice;
\\}
\\comptime {
\\ var array = [_:0]u8{ 1, 2, 3, 4 };
+ \\ var slice = array[2..6];
+ \\ _ = slice;
+ \\}
+ \\comptime {
+ \\ var array = [_]u8{ 1, 2, 3, 4 };
\\ var slice = array[2..5];
\\ _ = slice;
\\}
@@ -40,9 +45,10 @@ pub fn addCases(ctx: *TestContext) !void {
\\ _ = slice;
\\}
, &[_][]const u8{
- ":4:26: error: end index 5 out of bounds for slice of length 4",
- ":9:22: error: end index 5 out of bounds for array of length 4",
- ":14:22: error: start index 3 is larger than end index 2",
+ ":4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)",
+ ":9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)",
+ ":14:22: error: end index 5 out of bounds for array of length 4",
+ ":19:22: error: start index 3 is larger than end index 2",
});
}