Skip to content

AutoArrayHashMap: Alignment error when key type is single-member enum and value type is void #10618

@cryptocode

Description

@cryptocode

Zig Version

0.10.0-dev.295+f19b5ecf4

Steps to Reproduce

This occurs when the AutoArrayHashMap key type is an enum with a single member and the value type is void.

This construct is unlikely to be seen in real-world code, but occurred in a test-case where the hashmap was part of a larger structure taking an enum type argument.

const std = @import("std");

test "alignment error" {
    const E = enum { a };
    var map = std.AutoArrayHashMap(E, void).init(std.testing.allocator);
    defer map.deinit();
}

The compile error disappears if a) another enum member is added, or b) a value type is specified.

Expected Behavior

Successful compilation

Actual Behavior

Fails with

build/lib/zig/std/multi_array_list.zig:19:25: error: alignment must be >= 1
        bytes: [*]align(@alignOf(S)) u8 = undefined,
                        ^
build/lib/zig/std/multi_array_list.zig:19:9: note: referenced here
        bytes: [*]align(@alignOf(S)) u8 = undefined,
        ^
./repro.zig:5:44: note: referenced here
    var map = std.AutoArrayHashMap(E, void).init(std.testing.allocator);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    Status

    Uncategorized

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions