| ... | @@ -14,48 +14,7 @@ test { | ... | @@ -14,48 +14,7 @@ test { |
| 14 | _ = TrailerFlags; | 14 | _ = TrailerFlags; |
| 15 | } | 15 | } |
| 16 | | 16 | |
| 17 | pub fn tagName(v: anytype) []const u8 { | 17 | pub const tagName = @compileError("deprecated; use @tagName or @errorName directly"); |
| 18 | const T = @TypeOf(v); | | |
| 19 | switch (@typeInfo(T)) { | | |
| 20 | .ErrorSet => return @errorName(v), | | |
| 21 | else => return @tagName(v), | | |
| 22 | } | | |
| 23 | } | | |
| 24 | | | |
| 25 | test "std.meta.tagName" { | | |
| 26 | const E1 = enum { | | |
| 27 | A, | | |
| 28 | B, | | |
| 29 | }; | | |
| 30 | const E2 = enum(u8) { | | |
| 31 | C = 33, | | |
| 32 | D, | | |
| 33 | }; | | |
| 34 | const U1 = union(enum) { | | |
| 35 | G: u8, | | |
| 36 | H: u16, | | |
| 37 | }; | | |
| 38 | const U2 = union(E2) { | | |
| 39 | C: u8, | | |
| 40 | D: u16, | | |
| 41 | }; | | |
| 42 | | | |
| 43 | var u1g = U1{ .G = 0 }; | | |
| 44 | var u1h = U1{ .H = 0 }; | | |
| 45 | var u2a = U2{ .C = 0 }; | | |
| 46 | var u2b = U2{ .D = 0 }; | | |
| 47 | | | |
| 48 | try testing.expect(mem.eql(u8, tagName(E1.A), "A")); | | |
| 49 | try testing.expect(mem.eql(u8, tagName(E1.B), "B")); | | |
| 50 | try testing.expect(mem.eql(u8, tagName(E2.C), "C")); | | |
| 51 | try testing.expect(mem.eql(u8, tagName(E2.D), "D")); | | |
| 52 | try testing.expect(mem.eql(u8, tagName(error.E), "E")); | | |
| 53 | try testing.expect(mem.eql(u8, tagName(error.F), "F")); | | |
| 54 | try testing.expect(mem.eql(u8, tagName(u1g), "G")); | | |
| 55 | try testing.expect(mem.eql(u8, tagName(u1h), "H")); | | |
| 56 | try testing.expect(mem.eql(u8, tagName(u2a), "C")); | | |
| 57 | try testing.expect(mem.eql(u8, tagName(u2b), "D")); | | |
| 58 | } | | |
| 59 | | 18 | |
| 60 | /// Given an enum or tagged union, returns true if the comptime-supplied | 19 | /// Given an enum or tagged union, returns true if the comptime-supplied |
| 61 | /// string matches the name of the tag value. This match process should | 20 | /// string matches the name of the tag value. This match process should |