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
This commit is contained in:
mlugg
2023-04-20 00:55:52 +01:00
committed by Andrew Kelley
parent 31b6d14bf7
commit d5f1a8823e
3 changed files with 36 additions and 14 deletions

View File

@@ -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);
}