diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-03 21:05:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-03 21:05:10 -0700 |
| commit | 0893326e0ea9b261c5d334067c294c7d8972d5a1 (patch) | |
| tree | d91c43cbe138a37aca438f8adc6c747abafa346b /test/behavior/slice.zig | |
| parent | 71e0cca7a7957e2f024d2985318e478aa6fb1451 (diff) | |
| download | zig-0893326e0ea9b261c5d334067c294c7d8972d5a1.tar.gz zig-0893326e0ea9b261c5d334067c294c7d8972d5a1.zip | |
Sema: slice improvements
* resolve_inferred_alloc now gives a proper mutability attribute to the
corresponding alloc instruction. Previously, it would fail to mark
things const.
* slicing: fix the detection for when the end index equals the length
of the underlying object. Previously it was using `end - start` but
it should just use the end index directly. It also takes into account
when slicing a comptime-known slice.
* `Type.sentinel`: fix not handling all slice tags
Diffstat (limited to 'test/behavior/slice.zig')
| -rw-r--r-- | test/behavior/slice.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index 0b01139800..d4e8284751 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -192,3 +192,15 @@ test "compile time slice of pointer to hard coded address" { try expect(@ptrToInt(y) == 0x1400); try expect(y.len == 0x400); } + +test "slice string literal has correct type" { + comptime { + try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8); + const array = [_]i32{ 1, 2, 3, 4 }; + try expect(@TypeOf(array[0..]) == *const [4]i32); + } + var runtime_zero: usize = 0; + comptime try expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); + const array = [_]i32{ 1, 2, 3, 4 }; + comptime try expect(@TypeOf(array[runtime_zero..]) == []const i32); +} |
