Skip to content

std.EnumArray: edit return of iterator.next() (Reloaded) #24410

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

poypoyan
Copy link
Contributor

Fixes: #22506

(No changes from previous PR; just moved to a new branch so that master is sync for new contribution.)

The main fix is to replace return Entry{ with just return .{ in iterator.next() of EnumArray. The prior should actually work, but I think there is a deeper bug here: I see 3 "variants" of issue #19985:

const E = @Type(.{ .Enum = .{
    .tag_type = u0,
    .is_exhaustive = true,
    .fields = &.{.{ .name = "foo", .value = 0 }},
    .decls = &.{},
} });

const s: struct { E } = .{.foo};   // 1) original of #19955. compiles.
const s = struct { k: E }{ .k = .foo };   // 2) minimal replication of the current issue. does not compile!
const s: struct { k: E } = .{ .k = .foo };   // 3) minimal replication of my fix. compiles.

Thus my change in test/behavior/type.zig is to add variant 3) alongside 1). I am not knowledgeable in how compiler works so I cannot investigate further on why 2) doesn't work.

Other changes:

  • Moved EnumSet tests below EnumSet function.
  • Add test for the current issue below EnumArray function.

@poypoyan poypoyan force-pushed the fieldenum-onefield branch from d96cfd7 to 1b3e277 Compare July 11, 2025 22:11
@poypoyan poypoyan force-pushed the fieldenum-onefield branch from 1b3e277 to 13dfef6 Compare July 12, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.meta.FieldEnum for type with one field does not work in std.EnumArray
1 participant