File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -377,6 +377,32 @@ test "Type.Enum" {
377377 try testing .expectEqual (@as (u32 , 1 ), @intFromEnum (Bar .a ));
378378 try testing .expectEqual (@as (u32 , 5 ), @intFromEnum (Bar .b ));
379379 try testing .expectEqual (@as (u32 , 6 ), @intFromEnum (@as (Bar , @enumFromInt (6 ))));
380+
381+ { // from https://github.com/ziglang/zig/issues/19985
382+ { // enum with single field can be initialized.
383+ const E = @Type (.{ .@"enum" = .{
384+ .tag_type = u0 ,
385+ .is_exhaustive = true ,
386+ .fields = &.{.{ .name = "foo" , .value = 0 }},
387+ .decls = &.{},
388+ } });
389+ const s : struct { E } = .{.foo };
390+ try testing .expectEqual (.foo , s [0 ]);
391+ }
392+
393+ { // meta.FieldEnum() with single field
394+ const S = struct { foo : u8 };
395+ const Fe = std .meta .FieldEnum (S );
396+ var s : S = undefined ;
397+ const fe = std .meta .stringToEnum (Fe , "foo" ) orelse return error .InvalidField ;
398+ switch (fe ) {
399+ inline else = > | tag | {
400+ @field (s , @tagName (tag )) = 42 ;
401+ },
402+ }
403+ try testing .expectEqual (42 , s .foo );
404+ }
405+ }
380406}
381407
382408test "Type.Union" {
You can’t perform that action at this time.
0 commit comments