Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error using unusedCapacitySlice with ArrayListAligned if alignment > 1 #19724

Open
ehaas opened this issue Apr 21, 2024 · 0 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@ehaas
Copy link
Sponsor Contributor

ehaas commented Apr 21, 2024

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 ehaas added the bug Observed behavior contradicts documented or intended behavior label Apr 21, 2024
@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label Apr 21, 2024
@Vexu Vexu added this to the 0.13.0 milestone Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants