authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2021-01-11 10:56:18-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-01-30 13:19:52+02:00
log68ec54f386d387c5dd3f9dc4f0b5e14be6ae10a6
tree85e45ff4284fc836c299b88e0bf2eca61140bd4b
parent290efc074797e893678154efac61f94a38f6bfc1
signaturelock-open Commit is signed but in an unrecognized format.

std.meta: rename TagType to Tag


2 files changed, 14 insertions(+), 11 deletions(-)

lib/std/json.zig+1-1
......@@ -1138,7 +1138,7 @@ pub const TokenStream = struct {
11381138 }
11391139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.TagType(Token)) void {
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
11421142 const token = (p.next() catch unreachable).?;
11431143 debug.assert(std.meta.activeTag(token) == id);
11441144}
lib/std/meta.zig+13-10
......@@ -600,15 +600,18 @@ test "std.meta.FieldEnum" {
600600 expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
601601}
602602
603pub fn TagType(comptime T: type) type {
603// Deprecated: use Tag
604pub const TagType = Tag;
605
606pub fn Tag(comptime T: type) type {
604607 return switch (@typeInfo(T)) {
605608 .Enum => |info| info.tag_type,
606 .Union => |info| if (info.tag_type) |Tag| Tag else null,
609 .Union => |info| if (info.tag_type) |TheTag| TheTag else null,
607610 else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),
608611 };
609612}
610613
611test "std.meta.TagType" {
614test "std.meta.Tag" {
612615 const E = enum(u8) {
613616 C = 33,
614617 D,
......@@ -618,8 +621,8 @@ test "std.meta.TagType" {
618621 D: u16,
619622 };
620623
621 testing.expect(TagType(E) == u8);
622 testing.expect(TagType(U) == E);
624 testing.expect(Tag(E) == u8);
625 testing.expect(Tag(U) == E);
623626}
624627
625628///Returns the active tag of a tagged union
......@@ -694,13 +697,13 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
694697 }
695698 },
696699 .Union => |info| {
697 if (info.tag_type) |Tag| {
700 if (info.tag_type) |UnionTag| {
698701 const tag_a = activeTag(a);
699702 const tag_b = activeTag(b);
700703 if (tag_a != tag_b) return false;
701704
702705 inline for (info.fields) |field_info| {
703 if (@field(Tag, field_info.name) == tag_a) {
706 if (@field(UnionTag, field_info.name) == tag_a) {
704707 return eql(@field(a, field_info.name), @field(b, field_info.name));
705708 }
706709 }
......@@ -822,9 +825,9 @@ test "intToEnum with error return" {
822825
823826pub const IntToEnumError = error{InvalidEnumTag};
824827
825pub fn intToEnum(comptime Tag: type, tag_int: anytype) IntToEnumError!Tag {
826 inline for (@typeInfo(Tag).Enum.fields) |f| {
827 const this_tag_value = @field(Tag, f.name);
828pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTag {
829 inline for (@typeInfo(EnumTag).Enum.fields) |f| {
830 const this_tag_value = @field(EnumTag, f.name);
828831 if (tag_int == @enumToInt(this_tag_value)) {
829832 return this_tag_value;
830833 }