From b019a19b5546d51865175359ec1ae8e5aa3f4128 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Jan 2022 16:09:17 -0700 Subject: Sema: comptime loads and stores for `elem_ptr` The index is checked against actual array lengths, and now handles coerced or casted pointers to single items. --- test/behavior/array_llvm.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/behavior/array_llvm.zig') diff --git a/test/behavior/array_llvm.zig b/test/behavior/array_llvm.zig index 8e65045210..3fca269034 100644 --- a/test/behavior/array_llvm.zig +++ b/test/behavior/array_llvm.zig @@ -33,3 +33,15 @@ test "read/write through global variable array of struct fields initialized via }; try S.doTheTest(); } + +test "implicit cast single-item pointer" { + try testImplicitCastSingleItemPtr(); + comptime try testImplicitCastSingleItemPtr(); +} + +fn testImplicitCastSingleItemPtr() !void { + var byte: u8 = 100; + const slice = @as(*[1]u8, &byte)[0..]; + slice[0] += 1; + try expect(byte == 101); +} -- cgit v1.2.3