From d5f1a8823eb964c6149fc1d627ea6936d70ea7f1 Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 20 Apr 2023 00:55:52 +0100 Subject: Sema: allow ptr field access on pointer-to-array Also remove an incorrect piece of logic which allowed fetching the 'len' property on non-single-ptrs (e.g. many-ptrs) and add a corresponding compile error test case. Resolves: #4765 --- test/behavior/array.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/behavior/array.zig') diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 88a6ab947d..ec31d4a3fb 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -677,3 +677,13 @@ test "array of array agregate init" { var b = [1][10]u32{a} ** 2; try std.testing.expect(b[1][1] == 11); } + +test "pointer to array has ptr field" { + const arr: *const [5]u32 = &.{ 10, 20, 30, 40, 50 }; + try std.testing.expect(arr.ptr == @as([*]const u32, arr)); + try std.testing.expect(arr.ptr[0] == 10); + try std.testing.expect(arr.ptr[1] == 20); + try std.testing.expect(arr.ptr[2] == 30); + try std.testing.expect(arr.ptr[3] == 40); + try std.testing.expect(arr.ptr[4] == 50); +} -- cgit v1.2.3