| author | |
| committer | |
| log | 0b5f3c2ef96df02341cdf54f6eefb3cdb88781d8 |
| tree | 1a9a37f1a5fc96b56044f74c186101d5ac862654 |
| parent | 1637d8ac80b46599e276eb767208f54f0a30ccf0 |
| signature | Commit is signed but in an unrecognized format. |
26 files changed, 73 insertions(+), 83 deletions(-)
doc/langref.html.in+3-3| ... | ... | @@ -2909,15 +2909,15 @@ test "enum variant switch" { |
| 2909 | 2909 | expect(mem.eql(u8, what_is_it, "this is a number")); |
| 2910 | 2910 | } |
| 2911 | 2911 | |
| 2912 | // @TagType can be used to access the integer tag type of an enum. | |
| 2912 | // @typeInfo can be used to access the integer tag type of an enum. | |
| 2913 | 2913 | const Small = enum { |
| 2914 | 2914 | one, |
| 2915 | 2915 | two, |
| 2916 | 2916 | three, |
| 2917 | 2917 | four, |
| 2918 | 2918 | }; |
| 2919 | test "@TagType" { | |
| 2920 | expect(@TagType(Small) == u2); | |
| 2919 | test "std.meta.Tag" { | |
| 2920 | expect(@typeInfo(Small).Enum.tag_type == u2); | |
| 2921 | 2921 | } |
| 2922 | 2922 | |
| 2923 | 2923 | // @typeInfo tells us the field count and the fields names: |
lib/std/builtin.zig+1-1| ... | ... | @@ -175,7 +175,7 @@ pub const SourceLocation = struct { |
| 175 | 175 | column: u32, |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | pub const TypeId = @TagType(TypeInfo); | |
| 178 | pub const TypeId = std.meta.Tag(TypeInfo); | |
| 179 | 179 | |
| 180 | 180 | /// This data structure is used by the Zig language code generation and |
| 181 | 181 | /// therefore must be kept in sync with the compiler implementation. |
lib/std/c/ast.zig+1-1| ... | ... | @@ -110,7 +110,7 @@ pub const Error = union(enum) { |
| 110 | 110 | |
| 111 | 111 | pub const ExpectedToken = struct { |
| 112 | 112 | token: TokenIndex, |
| 113 | expected_id: @TagType(Token.Id), | |
| 113 | expected_id: std.meta.Tag(Token.Id), | |
| 114 | 114 | |
| 115 | 115 | pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void { |
| 116 | 116 | const found_token = tree.tokens.at(self.token); |
lib/std/c/parse.zig+3-3| ... | ... | @@ -26,7 +26,7 @@ pub const Options = struct { |
| 26 | 26 | None, |
| 27 | 27 | |
| 28 | 28 | /// Some warnings are errors |
| 29 | Some: []@TagType(ast.Error), | |
| 29 | Some: []std.meta.Tag(ast.Error), | |
| 30 | 30 | |
| 31 | 31 | /// All warnings are errors |
| 32 | 32 | All, |
| ... | ... | @@ -1363,7 +1363,7 @@ const Parser = struct { |
| 1363 | 1363 | return &node.base; |
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | fn eatToken(parser: *Parser, id: @TagType(Token.Id)) ?TokenIndex { | |
| 1366 | fn eatToken(parser: *Parser, id: std.meta.Tag(Token.Id)) ?TokenIndex { | |
| 1367 | 1367 | while (true) { |
| 1368 | 1368 | switch ((parser.it.next() orelse return null).id) { |
| 1369 | 1369 | .LineComment, .MultiLineComment, .Nl => continue, |
| ... | ... | @@ -1377,7 +1377,7 @@ const Parser = struct { |
| 1377 | 1377 | } |
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | fn expectToken(parser: *Parser, id: @TagType(Token.Id)) Error!TokenIndex { | |
| 1380 | fn expectToken(parser: *Parser, id: std.meta.Tag(Token.Id)) Error!TokenIndex { | |
| 1381 | 1381 | while (true) { |
| 1382 | 1382 | switch ((parser.it.next() orelse return error.ParseError).id) { |
| 1383 | 1383 | .LineComment, .MultiLineComment, .Nl => continue, |
lib/std/c/tokenizer.zig+2-2| ... | ... | @@ -131,7 +131,7 @@ pub const Token = struct { |
| 131 | 131 | Keyword_error, |
| 132 | 132 | Keyword_pragma, |
| 133 | 133 | |
| 134 | pub fn symbol(id: @TagType(Id)) []const u8 { | |
| 134 | pub fn symbol(id: std.meta.TagType(Id)) []const u8 { | |
| 135 | 135 | return switch (id) { |
| 136 | 136 | .Invalid => "Invalid", |
| 137 | 137 | .Eof => "Eof", |
| ... | ... | @@ -347,7 +347,7 @@ pub const Token = struct { |
| 347 | 347 | pub const Tokenizer = struct { |
| 348 | 348 | buffer: []const u8, |
| 349 | 349 | index: usize = 0, |
| 350 | prev_tok_id: @TagType(Token.Id) = .Invalid, | |
| 350 | prev_tok_id: std.meta.TagType(Token.Id) = .Invalid, | |
| 351 | 351 | pp_directive: bool = false, |
| 352 | 352 | |
| 353 | 353 | pub fn next(self: *Tokenizer) Token { |
lib/std/hash/auto_hash.zig+1-1| ... | ... | @@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 { |
| 239 | 239 | |
| 240 | 240 | test "typeContainsSlice" { |
| 241 | 241 | comptime { |
| 242 | testing.expect(!typeContainsSlice(@TagType(std.builtin.TypeInfo))); | |
| 242 | testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo))); | |
| 243 | 243 | |
| 244 | 244 | testing.expect(typeContainsSlice([]const u8)); |
| 245 | 245 | testing.expect(!typeContainsSlice(u8)); |
lib/std/json.zig+2-2| ... | ... | @@ -246,7 +246,7 @@ pub const StreamingParser = struct { |
| 246 | 246 | // Only call this function to generate array/object final state. |
| 247 | 247 | pub fn fromInt(x: anytype) State { |
| 248 | 248 | debug.assert(x == 0 or x == 1); |
| 249 | const T = @TagType(State); | |
| 249 | const T = std.meta.Tag(State); | |
| 250 | 250 | return @intToEnum(State, @intCast(T, x)); |
| 251 | 251 | } |
| 252 | 252 | }; |
| ... | ... | @@ -1782,7 +1782,7 @@ test "parseFree descends into tagged union" { |
| 1782 | 1782 | }; |
| 1783 | 1783 | // use a string with unicode escape so we know result can't be a reference to global constant |
| 1784 | 1784 | const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options); |
| 1785 | testing.expectEqual(@TagType(T).string, @as(@TagType(T), r)); | |
| 1785 | testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r)); | |
| 1786 | 1786 | testing.expectEqualSlices(u8, "withąunicode", r.string); |
| 1787 | 1787 | testing.expectEqual(@as(usize, 0), fail_alloc.deallocations); |
| 1788 | 1788 | parseFree(T, r, options); |
lib/std/meta.zig+5-5| ... | ... | @@ -606,7 +606,7 @@ pub const TagType = Tag; |
| 606 | 606 | pub fn Tag(comptime T: type) type { |
| 607 | 607 | return switch (@typeInfo(T)) { |
| 608 | 608 | .Enum => |info| info.tag_type, |
| 609 | .Union => |info| if (info.tag_type) |TheTag| TheTag else null, | |
| 609 | .Union => |info| info.tag_type orelse @compileError(@typeName(T) ++ " has no tag type"), | |
| 610 | 610 | else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"), |
| 611 | 611 | }; |
| 612 | 612 | } |
| ... | ... | @@ -626,9 +626,9 @@ test "std.meta.Tag" { |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | ///Returns the active tag of a tagged union |
| 629 | pub fn activeTag(u: anytype) @TagType(@TypeOf(u)) { | |
| 629 | pub fn activeTag(u: anytype) Tag(@TypeOf(u)) { | |
| 630 | 630 | const T = @TypeOf(u); |
| 631 | return @as(@TagType(T), u); | |
| 631 | return @as(Tag(T), u); | |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | test "std.meta.activeTag" { |
| ... | ... | @@ -653,11 +653,11 @@ const TagPayloadType = TagPayload; |
| 653 | 653 | |
| 654 | 654 | ///Given a tagged union type, and an enum, return the type of the union |
| 655 | 655 | /// field corresponding to the enum tag. |
| 656 | pub fn TagPayload(comptime U: type, tag: @TagType(U)) type { | |
| 656 | pub fn TagPayload(comptime U: type, tag: Tag(U)) type { | |
| 657 | 657 | testing.expect(trait.is(.Union)(U)); |
| 658 | 658 | |
| 659 | 659 | const info = @typeInfo(U).Union; |
| 660 | const tag_info = @typeInfo(@TagType(U)).Enum; | |
| 660 | const tag_info = @typeInfo(Tag(U)).Enum; | |
| 661 | 661 | |
| 662 | 662 | inline for (info.fields) |field_info| { |
| 663 | 663 | if (comptime mem.eql(u8, field_info.name, @tagName(tag))) |
lib/std/meta/trailer_flags.zig+1-1| ... | ... | @@ -146,7 +146,7 @@ test "TrailerFlags" { |
| 146 | 146 | b: bool, |
| 147 | 147 | c: u64, |
| 148 | 148 | }); |
| 149 | testing.expectEqual(u2, @TagType(Flags.FieldEnum)); | |
| 149 | testing.expectEqual(u2, meta.Tag(Flags.FieldEnum)); | |
| 150 | 150 | |
| 151 | 151 | var flags = Flags.init(.{ |
| 152 | 152 | .b = true, |
lib/std/testing.zig+3-3| ... | ... | @@ -119,10 +119,10 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 119 | 119 | @compileError("Unable to compare untagged union values"); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | const TagType = @TagType(@TypeOf(expected)); | |
| 122 | const Tag = std.meta.Tag(@TypeOf(expected)); | |
| 123 | 123 | |
| 124 | const expectedTag = @as(TagType, expected); | |
| 125 | const actualTag = @as(TagType, actual); | |
| 124 | const expectedTag = @as(Tag, expected); | |
| 125 | const actualTag = @as(Tag, actual); | |
| 126 | 126 | |
| 127 | 127 | expectEqual(expectedTag, actualTag); |
| 128 | 128 |
lib/std/zig/parser_test.zig+1-1| ... | ... | @@ -3822,7 +3822,7 @@ fn testCanonical(source: []const u8) !void { |
| 3822 | 3822 | return testTransform(source, source); |
| 3823 | 3823 | } |
| 3824 | 3824 | |
| 3825 | const Error = @TagType(std.zig.ast.Error); | |
| 3825 | const Error = std.meta.Tag(std.zig.ast.Error); | |
| 3826 | 3826 | |
| 3827 | 3827 | fn testError(source: []const u8, expected_errors: []const Error) !void { |
| 3828 | 3828 | const tree = try std.zig.parse(std.testing.allocator, source); |
src/DepTokenizer.zig+2-2| ... | ... | @@ -266,11 +266,11 @@ pub fn next(self: *Tokenizer) ?Token { |
| 266 | 266 | unreachable; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | fn errorPosition(comptime id: @TagType(Token), index: usize, bytes: []const u8) Token { | |
| 269 | fn errorPosition(comptime id: std.meta.Tag(Token), index: usize, bytes: []const u8) Token { | |
| 270 | 270 | return @unionInit(Token, @tagName(id), .{ .index = index, .bytes = bytes }); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | fn errorIllegalChar(comptime id: @TagType(Token), index: usize, char: u8) Token { | |
| 273 | fn errorIllegalChar(comptime id: std.meta.Tag(Token), index: usize, char: u8) Token { | |
| 274 | 274 | return @unionInit(Token, @tagName(id), .{ .index = index, .char = char }); |
| 275 | 275 | } |
| 276 | 276 |
src/link/MachO/commands.zig+1-1| ... | ... | @@ -140,7 +140,7 @@ pub const LoadCommand = union(enum) { |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | fn eql(self: LoadCommand, other: LoadCommand) bool { |
| 143 | if (@as(@TagType(LoadCommand), self) != @as(@TagType(LoadCommand), other)) return false; | |
| 143 | if (@as(meta.Tag(LoadCommand), self) != @as(meta.Tag(LoadCommand), other)) return false; | |
| 144 | 144 | return switch (self) { |
| 145 | 145 | .DyldInfoOnly => |x| meta.eql(x, other.DyldInfoOnly), |
| 146 | 146 | .Symtab => |x| meta.eql(x, other.Symtab), |
src/stage1/analyze.cpp+1-1| ... | ... | @@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3267 | 3267 | |
| 3268 | 3268 | tag_type = new_type_table_entry(ZigTypeIdEnum); |
| 3269 | 3269 | buf_resize(&tag_type->name, 0); |
| 3270 | buf_appendf(&tag_type->name, "@typeInfo(%s).Enum.tag_type", buf_ptr(&union_type->name)); | |
| 3270 | buf_appendf(&tag_type->name, "@typeInfo(%s).Union.tag_type.?", buf_ptr(&union_type->name)); | |
| 3271 | 3271 | tag_type->llvm_type = tag_int_type->llvm_type; |
| 3272 | 3272 | tag_type->llvm_di_type = tag_int_type->llvm_di_type; |
| 3273 | 3273 | tag_type->abi_size = tag_int_type->abi_size; |
src/test.zig+2-2| ... | ... | @@ -750,7 +750,7 @@ pub const TestContext = struct { |
| 750 | 750 | |
| 751 | 751 | for (actual_errors.list) |actual_error| { |
| 752 | 752 | for (case_error_list) |case_msg, i| { |
| 753 | const ex_tag: @TagType(@TypeOf(case_msg)) = case_msg; | |
| 753 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; | |
| 754 | 754 | switch (actual_error) { |
| 755 | 755 | .src => |actual_msg| { |
| 756 | 756 | for (actual_msg.notes) |*note| { |
| ... | ... | @@ -789,7 +789,7 @@ pub const TestContext = struct { |
| 789 | 789 | } |
| 790 | 790 | while (notes_to_check.popOrNull()) |note| { |
| 791 | 791 | for (case_error_list) |case_msg, i| { |
| 792 | const ex_tag: @TagType(@TypeOf(case_msg)) = case_msg; | |
| 792 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; | |
| 793 | 793 | switch (note.*) { |
| 794 | 794 | .src => |actual_msg| { |
| 795 | 795 | for (actual_msg.notes) |*sub_note| { |
src/translate_c.zig+1-1| ... | ... | @@ -3288,7 +3288,7 @@ const ClangFunctionType = union(enum) { |
| 3288 | 3288 | NoProto: *const clang.FunctionType, |
| 3289 | 3289 | |
| 3290 | 3290 | fn getReturnType(self: @This()) clang.QualType { |
| 3291 | switch (@as(@TagType(@This()), self)) { | |
| 3291 | switch (@as(std.meta.Tag(@This()), self)) { | |
| 3292 | 3292 | .Proto => return self.Proto.getReturnType(), |
| 3293 | 3293 | .NoProto => return self.NoProto.getReturnType(), |
| 3294 | 3294 | } |
src/type.zig+1-1| ... | ... | @@ -110,7 +110,7 @@ pub const Type = extern union { |
| 110 | 110 | |
| 111 | 111 | pub fn tag(self: Type) Tag { |
| 112 | 112 | if (self.tag_if_small_enough < Tag.no_payload_count) { |
| 113 | return @intToEnum(Tag, @intCast(@TagType(Tag), self.tag_if_small_enough)); | |
| 113 | return @intToEnum(Tag, @intCast(std.meta.Tag(Tag), self.tag_if_small_enough)); | |
| 114 | 114 | } else { |
| 115 | 115 | return self.ptr_otherwise.tag; |
| 116 | 116 | } |
src/value.zig+1-1| ... | ... | @@ -223,7 +223,7 @@ pub const Value = extern union { |
| 223 | 223 | |
| 224 | 224 | pub fn tag(self: Value) Tag { |
| 225 | 225 | if (self.tag_if_small_enough < Tag.no_payload_count) { |
| 226 | return @intToEnum(Tag, @intCast(@TagType(Tag), self.tag_if_small_enough)); | |
| 226 | return @intToEnum(Tag, @intCast(std.meta.Tag(Tag), self.tag_if_small_enough)); | |
| 227 | 227 | } else { |
| 228 | 228 | return self.ptr_otherwise.tag; |
| 229 | 229 | } |
test/compile_errors.zig+4-16| ... | ... | @@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 323 | 323 | \\ e: E, |
| 324 | 324 | \\}; |
| 325 | 325 | \\export fn entry() void { |
| 326 | \\ if (@TagType(E) != u8) @compileError("did not infer u8 tag type"); | |
| 326 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); | |
| 327 | 327 | \\ const s: S = undefined; |
| 328 | 328 | \\} |
| 329 | 329 | , &[_][]const u8{ |
| ... | ... | @@ -2728,7 +2728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2728 | 2728 | \\const InvalidToken = struct {}; |
| 2729 | 2729 | \\const ExpectedVarDeclOrFn = struct {}; |
| 2730 | 2730 | , &[_][]const u8{ |
| 2731 | "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'", | |
| 2731 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", | |
| 2732 | 2732 | }); |
| 2733 | 2733 | |
| 2734 | 2734 | cases.addTest("binary OR operator on error sets", |
| ... | ... | @@ -7462,24 +7462,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7462 | 7462 | "tmp.zig:4:5: note: declared here", |
| 7463 | 7463 | }); |
| 7464 | 7464 | |
| 7465 | cases.add("@TagType when union has no attached enum", | |
| 7466 | \\const Foo = union { | |
| 7467 | \\ A: i32, | |
| 7468 | \\}; | |
| 7469 | \\export fn entry() void { | |
| 7470 | \\ const x = @TagType(Foo); | |
| 7471 | \\} | |
| 7472 | , &[_][]const u8{ | |
| 7473 | "tmp.zig:5:24: error: union 'Foo' has no tag", | |
| 7474 | "tmp.zig:1:13: note: consider 'union(enum)' here", | |
| 7475 | }); | |
| 7476 | ||
| 7477 | 7465 | cases.add("non-integer tag type to automatic union enum", |
| 7478 | 7466 | \\const Foo = union(enum(f32)) { |
| 7479 | 7467 | \\ A: i32, |
| 7480 | 7468 | \\}; |
| 7481 | 7469 | \\export fn entry() void { |
| 7482 | \\ const x = @TagType(Foo); | |
| 7470 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | |
| 7483 | 7471 | \\} |
| 7484 | 7472 | , &[_][]const u8{ |
| 7485 | 7473 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| ... | ... | @@ -7490,7 +7478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7490 | 7478 | \\ A: i32, |
| 7491 | 7479 | \\}; |
| 7492 | 7480 | \\export fn entry() void { |
| 7493 | \\ const x = @TagType(Foo); | |
| 7481 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | |
| 7494 | 7482 | \\} |
| 7495 | 7483 | , &[_][]const u8{ |
| 7496 | 7484 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
test/runtime_safety.zig+1-1| ... | ... | @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 74 | 74 | \\pub fn main() void { |
| 75 | 75 | \\ var u: U = undefined; |
| 76 | 76 | \\ @memset(@ptrCast([*]u8, &u), 0x55, @sizeOf(U)); |
| 77 | \\ var t: @TagType(U) = u; | |
| 77 | \\ var t: @typeInfo(U).Union.tag_type.? = u; | |
| 78 | 78 | \\ var n = @tagName(t); |
| 79 | 79 | \\} |
| 80 | 80 | ); |
test/stage1/behavior/bugs/1322.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ const C = struct {}; |
| 13 | 13 | |
| 14 | 14 | test "tagged union with all void fields but a meaningful tag" { |
| 15 | 15 | var a: A = A{ .b = B{ .c = C{} } }; |
| 16 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c); | |
| 16 | std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c); | |
| 17 | 17 | a = A{ .b = B.None }; |
| 18 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None); | |
| 18 | std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None); | |
| 19 | 19 | } |
test/stage1/behavior/enum.zig+8-7| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | const Tag = @import("std").meta.Tag; | |
| 3 | 4 | |
| 4 | 5 | test "extern enum" { |
| 5 | 6 | const S = struct { |
| ... | ... | @@ -827,12 +828,12 @@ test "set enum tag type" { |
| 827 | 828 | { |
| 828 | 829 | var x = Small.One; |
| 829 | 830 | x = Small.Two; |
| 830 | comptime expect(@TagType(Small) == u2); | |
| 831 | comptime expect(Tag(Small) == u2); | |
| 831 | 832 | } |
| 832 | 833 | { |
| 833 | 834 | var x = Small2.One; |
| 834 | 835 | x = Small2.Two; |
| 835 | comptime expect(@TagType(Small2) == u2); | |
| 836 | comptime expect(Tag(Small2) == u2); | |
| 836 | 837 | } |
| 837 | 838 | } |
| 838 | 839 | |
| ... | ... | @@ -905,11 +906,11 @@ fn getC(data: *const BitFieldOfEnums) C { |
| 905 | 906 | } |
| 906 | 907 | |
| 907 | 908 | test "casting enum to its tag type" { |
| 908 | testCastEnumToTagType(Small2.Two); | |
| 909 | comptime testCastEnumToTagType(Small2.Two); | |
| 909 | testCastEnumTag(Small2.Two); | |
| 910 | comptime testCastEnumTag(Small2.Two); | |
| 910 | 911 | } |
| 911 | 912 | |
| 912 | fn testCastEnumToTagType(value: Small2) void { | |
| 913 | fn testCastEnumTag(value: Small2) void { | |
| 913 | 914 | expect(@enumToInt(value) == 1); |
| 914 | 915 | } |
| 915 | 916 | |
| ... | ... | @@ -1163,14 +1164,14 @@ test "enum with comptime_int tag type" { |
| 1163 | 1164 | Two = 2, |
| 1164 | 1165 | Three = 1, |
| 1165 | 1166 | }; |
| 1166 | comptime expect(@TagType(Enum) == comptime_int); | |
| 1167 | comptime expect(Tag(Enum) == comptime_int); | |
| 1167 | 1168 | } |
| 1168 | 1169 | |
| 1169 | 1170 | test "enum with one member default to u0 tag type" { |
| 1170 | 1171 | const E0 = enum { |
| 1171 | 1172 | X, |
| 1172 | 1173 | }; |
| 1173 | comptime expect(@TagType(E0) == u0); | |
| 1174 | comptime expect(Tag(E0) == u0); | |
| 1174 | 1175 | } |
| 1175 | 1176 | |
| 1176 | 1177 | test "tagName on enum literals" { |
test/stage1/behavior/type_info.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ test "type info: tag type, void info" { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn testBasic() void { |
| 17 | expect(@TagType(TypeInfo) == TypeId); | |
| 17 | expect(@typeInfo(TypeInfo).Union.tag_type == TypeId); | |
| 18 | 18 | const void_info = @typeInfo(void); |
| 19 | 19 | expect(void_info == TypeId.Void); |
| 20 | 20 | expect(void_info.Void == {}); |
test/stage1/behavior/union.zig+23-22| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | 3 | const expectEqual = std.testing.expectEqual; |
| 4 | const Tag = std.meta.Tag; | |
| 4 | 5 | |
| 5 | 6 | const Value = union(enum) { |
| 6 | 7 | Int: u64, |
| ... | ... | @@ -128,7 +129,7 @@ const MultipleChoice = union(enum(u32)) { |
| 128 | 129 | test "simple union(enum(u32))" { |
| 129 | 130 | var x = MultipleChoice.C; |
| 130 | 131 | expect(x == MultipleChoice.C); |
| 131 | expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60); | |
| 132 | expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60); | |
| 132 | 133 | } |
| 133 | 134 | |
| 134 | 135 | const MultipleChoice2 = union(enum(u32)) { |
| ... | ... | @@ -144,13 +145,13 @@ const MultipleChoice2 = union(enum(u32)) { |
| 144 | 145 | }; |
| 145 | 146 | |
| 146 | 147 | test "union(enum(u32)) with specified and unspecified tag values" { |
| 147 | comptime expect(@TagType(@TagType(MultipleChoice2)) == u32); | |
| 148 | comptime expect(Tag(Tag(MultipleChoice2)) == u32); | |
| 148 | 149 | testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 149 | 150 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 153 | expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60); | |
| 154 | expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60); | |
| 154 | 155 | expect(1123 == switch (x) { |
| 155 | 156 | MultipleChoice2.A => 1, |
| 156 | 157 | MultipleChoice2.B => 2, |
| ... | ... | @@ -204,11 +205,11 @@ test "union field access gives the enum values" { |
| 204 | 205 | } |
| 205 | 206 | |
| 206 | 207 | test "cast union to tag type of union" { |
| 207 | testCastUnionToTagType(TheUnion{ .B = 1234 }); | |
| 208 | comptime testCastUnionToTagType(TheUnion{ .B = 1234 }); | |
| 208 | testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 209 | comptime testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 209 | 210 | } |
| 210 | 211 | |
| 211 | fn testCastUnionToTagType(x: TheUnion) void { | |
| 212 | fn testCastUnionToTag(x: TheUnion) void { | |
| 212 | 213 | expect(@as(TheTag, x) == TheTag.B); |
| 213 | 214 | } |
| 214 | 215 | |
| ... | ... | @@ -298,7 +299,7 @@ const TaggedUnionWithAVoid = union(enum) { |
| 298 | 299 | |
| 299 | 300 | fn testTaggedUnionInit(x: anytype) bool { |
| 300 | 301 | const y = TaggedUnionWithAVoid{ .A = x }; |
| 301 | return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A; | |
| 302 | return @as(Tag(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A; | |
| 302 | 303 | } |
| 303 | 304 | |
| 304 | 305 | pub const UnionEnumNoPayloads = union(enum) { |
| ... | ... | @@ -309,8 +310,8 @@ pub const UnionEnumNoPayloads = union(enum) { |
| 309 | 310 | test "tagged union with no payloads" { |
| 310 | 311 | const a = UnionEnumNoPayloads{ .B = {} }; |
| 311 | 312 | switch (a) { |
| 312 | @TagType(UnionEnumNoPayloads).A => @panic("wrong"), | |
| 313 | @TagType(UnionEnumNoPayloads).B => {}, | |
| 313 | Tag(UnionEnumNoPayloads).A => @panic("wrong"), | |
| 314 | Tag(UnionEnumNoPayloads).B => {}, | |
| 314 | 315 | } |
| 315 | 316 | } |
| 316 | 317 | |
| ... | ... | @@ -325,9 +326,9 @@ test "union with only 1 field casted to its enum type" { |
| 325 | 326 | }; |
| 326 | 327 | |
| 327 | 328 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 328 | const Tag = @TagType(Expr); | |
| 329 | comptime expect(@TagType(Tag) == u0); | |
| 330 | var t = @as(Tag, e); | |
| 329 | const ExprTag = Tag(Expr); | |
| 330 | comptime expect(Tag(ExprTag) == u0); | |
| 331 | var t = @as(ExprTag, e); | |
| 331 | 332 | expect(t == Expr.Literal); |
| 332 | 333 | } |
| 333 | 334 | |
| ... | ... | @@ -337,17 +338,17 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 337 | 338 | Bool: bool, |
| 338 | 339 | }; |
| 339 | 340 | |
| 340 | const Tag = enum(comptime_int) { | |
| 341 | const ExprTag = enum(comptime_int) { | |
| 341 | 342 | Literal = 33, |
| 342 | 343 | }; |
| 343 | 344 | |
| 344 | const Expr = union(Tag) { | |
| 345 | const Expr = union(ExprTag) { | |
| 345 | 346 | Literal: Literal, |
| 346 | 347 | }; |
| 347 | 348 | |
| 348 | 349 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 349 | comptime expect(@TagType(Tag) == comptime_int); | |
| 350 | var t = @as(Tag, e); | |
| 350 | comptime expect(Tag(ExprTag) == comptime_int); | |
| 351 | var t = @as(ExprTag, e); | |
| 351 | 352 | expect(t == Expr.Literal); |
| 352 | 353 | expect(@enumToInt(t) == 33); |
| 353 | 354 | comptime expect(@enumToInt(t) == 33); |
| ... | ... | @@ -501,7 +502,7 @@ test "union with one member defaults to u0 tag type" { |
| 501 | 502 | const U0 = union(enum) { |
| 502 | 503 | X: u32, |
| 503 | 504 | }; |
| 504 | comptime expect(@TagType(@TagType(U0)) == u0); | |
| 505 | comptime expect(Tag(Tag(U0)) == u0); | |
| 505 | 506 | } |
| 506 | 507 | |
| 507 | 508 | test "union with comptime_int tag" { |
| ... | ... | @@ -510,7 +511,7 @@ test "union with comptime_int tag" { |
| 510 | 511 | Y: u16, |
| 511 | 512 | Z: u8, |
| 512 | 513 | }; |
| 513 | comptime expect(@TagType(@TagType(Union)) == comptime_int); | |
| 514 | comptime expect(Tag(Tag(Union)) == comptime_int); | |
| 514 | 515 | } |
| 515 | 516 | |
| 516 | 517 | test "extern union doesn't trigger field check at comptime" { |
| ... | ... | @@ -591,7 +592,7 @@ test "function call result coerces from tagged union to the tag" { |
| 591 | 592 | Two: usize, |
| 592 | 593 | }; |
| 593 | 594 | |
| 594 | const ArchTag = @TagType(Arch); | |
| 595 | const ArchTag = Tag(Arch); | |
| 595 | 596 | |
| 596 | 597 | fn doTheTest() void { |
| 597 | 598 | var x: ArchTag = getArch1(); |
| ... | ... | @@ -696,8 +697,8 @@ test "cast from pointer to anonymous struct to pointer to union" { |
| 696 | 697 | |
| 697 | 698 | test "method call on an empty union" { |
| 698 | 699 | const S = struct { |
| 699 | const MyUnion = union(Tag) { | |
| 700 | pub const Tag = enum { X1, X2 }; | |
| 700 | const MyUnion = union(MyUnionTag) { | |
| 701 | pub const MyUnionTag = enum { X1, X2 }; | |
| 701 | 702 | X1: [0]u8, |
| 702 | 703 | X2: [0]u8, |
| 703 | 704 | |
| ... | ... | @@ -797,7 +798,7 @@ test "union enum type gets a separate scope" { |
| 797 | 798 | }; |
| 798 | 799 | |
| 799 | 800 | fn doTheTest() void { |
| 800 | expect(!@hasDecl(@TagType(U), "foo")); | |
| 801 | expect(!@hasDecl(Tag(U), "foo")); | |
| 801 | 802 | } |
| 802 | 803 | }; |
| 803 | 804 |
test/tests.zig+1-1| ... | ... | @@ -499,7 +499,7 @@ pub fn addPkgTests( |
| 499 | 499 | if (skip_single_threaded and test_target.single_threaded) |
| 500 | 500 | continue; |
| 501 | 501 | |
| 502 | const ArchTag = @TagType(builtin.Arch); | |
| 502 | const ArchTag = std.meta.Tag(builtin.Arch); | |
| 503 | 503 | if (test_target.disable_native and |
| 504 | 504 | test_target.target.getOsTag() == std.Target.current.os.tag and |
| 505 | 505 | test_target.target.getCpuArch() == std.Target.current.cpu.arch) |
tools/process_headers.zig+1-1| ... | ... | @@ -47,7 +47,7 @@ const MultiAbi = union(enum) { |
| 47 | 47 | fn eql(a: MultiAbi, b: MultiAbi) bool { |
| 48 | 48 | if (@enumToInt(a) != @enumToInt(b)) |
| 49 | 49 | return false; |
| 50 | if (@TagType(MultiAbi)(a) != .specific) | |
| 50 | if (std.meta.Tag(MultiAbi)(a) != .specific) | |
| 51 | 51 | return true; |
| 52 | 52 | return a.specific == b.specific; |
| 53 | 53 | } |