-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Zig Version
0.14.0-dev.2647+5322459a0
Steps to Reproduce and Observed Behavior
Using an enum generated by std.meta.FieldEnum
from a type with exactly one field in a std.EnumArray
fails to compile if iterator.next()
is called.
Example
const std = @import("std");
const A = struct {
x: u32,
// y: u32, // it works if A has a second field, or if A has no fields
};
const AEnum = std.meta.FieldEnum(A);
const MyEnum = enum { x };
pub fn main() void {
// this doesn't compile
var a = std.EnumArray(AEnum, u32).initFill(123);
var it = a.iterator();
while (it.next()) |n| _ = n;
// this compiles
var b = std.EnumArray(MyEnum, u32).initFill(123);
var it2 = b.iterator();
while (it2.next()) |n| _ = n;
}
fails to compile with the error message
/home/j/Programs/zig-linux-x86_64-0.14.0-dev.2647+5322459a0/lib/std/enums.zig:1158:39: error: value stored in comptime field does not match the default value of the field
.key = Indexer.keyForIndex(index),
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/home/j/Programs/zig-linux-x86_64-0.14.0-dev.2647+5322459a0/lib/std/enums.zig:1141:13: note: default value set here
key: Key,
Expected Behavior
I would expect it to compile and behave like an enum implemented by hand.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.