zig icon indicating copy to clipboard operation
zig copied to clipboard

Compile error using `unusedCapacitySlice` with `ArrayListAligned` if alignment > 1

Open ehaas opened this issue 1 year ago • 0 comments

Zig Version

0.13.0-dev.4+c7ffdbcd4

Steps to Reproduce and Observed Behavior

const std = @import("std");
test {
    var list = std.ArrayListAligned(u8, 4).init(std.testing.allocator);
    defer list.deinit();
    try list.appendNTimes(1, 4);
    _ = list.unusedCapacitySlice();
}
local/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/array_list.zig:570:41: error: expected type '[]align(4) u8', found '[]u8'
            return self.allocatedSlice()[self.items.len..];
                   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
local/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/array_list.zig:570:41: note: pointer alignment '1' cannot cast into pointer alignment '4'
local/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/array_list.zig:569:48: note: function return type declared here
        pub fn unusedCapacitySlice(self: Self) Slice {
                                               ^~~~~
referenced by:
    test_0: test.zig:6:13
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Expected Behavior

Function should return either return an unaligned slice, or assert correct alignment and return a slice with the same alignment as the array list.

ehaas avatar Apr 21 '24 16:04 ehaas