diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-08-28 02:35:53 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-08-28 08:39:59 +0100 |
| commit | 0fe3fd01ddc2cd49c6a2b939577d16b9d2c65ea9 (patch) | |
| tree | 2c07fddf2b6230360fe618c4de192bc2d24eeaf7 /test/behavior/type.zig | |
| parent | 1a178d499537b922ff05c5d0186ed5a00dbb1a9b (diff) | |
| download | zig-0fe3fd01ddc2cd49c6a2b939577d16b9d2c65ea9.tar.gz zig-0fe3fd01ddc2cd49c6a2b939577d16b9d2c65ea9.zip | |
std: update `std.builtin.Type` fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.
This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
Diffstat (limited to 'test/behavior/type.zig')
| -rw-r--r-- | test/behavior/type.zig | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/test/behavior/type.zig b/test/behavior/type.zig index ba29640774..4ebcfa7eee 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -11,32 +11,32 @@ fn testTypes(comptime types: []const type) !void { } test "Type.MetaType" { - try testing.expect(type == @Type(.{ .Type = {} })); + try testing.expect(type == @Type(.{ .type = {} })); try testTypes(&[_]type{type}); } test "Type.Void" { - try testing.expect(void == @Type(.{ .Void = {} })); + try testing.expect(void == @Type(.{ .void = {} })); try testTypes(&[_]type{void}); } test "Type.Bool" { - try testing.expect(bool == @Type(.{ .Bool = {} })); + try testing.expect(bool == @Type(.{ .bool = {} })); try testTypes(&[_]type{bool}); } test "Type.NoReturn" { - try testing.expect(noreturn == @Type(.{ .NoReturn = {} })); + try testing.expect(noreturn == @Type(.{ .noreturn = {} })); try testTypes(&[_]type{noreturn}); } test "Type.Int" { - try testing.expect(u1 == @Type(.{ .Int = .{ .signedness = .unsigned, .bits = 1 } })); - try testing.expect(i1 == @Type(.{ .Int = .{ .signedness = .signed, .bits = 1 } })); - try testing.expect(u8 == @Type(.{ .Int = .{ .signedness = .unsigned, .bits = 8 } })); - try testing.expect(i8 == @Type(.{ .Int = .{ .signedness = .signed, .bits = 8 } })); - try testing.expect(u64 == @Type(.{ .Int = .{ .signedness = .unsigned, .bits = 64 } })); - try testing.expect(i64 == @Type(.{ .Int = .{ .signedness = .signed, .bits = 64 } })); + try testing.expect(u1 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 1 } })); + try testing.expect(i1 == @Type(.{ .int = .{ .signedness = .signed, .bits = 1 } })); + try testing.expect(u8 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 8 } })); + try testing.expect(i8 == @Type(.{ .int = .{ .signedness = .signed, .bits = 8 } })); + try testing.expect(u64 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 64 } })); + try testing.expect(i64 == @Type(.{ .int = .{ .signedness = .signed, .bits = 64 } })); try testTypes(&[_]type{ u8, u32, i64 }); } @@ -105,31 +105,31 @@ test "Type.Pointer" { } test "Type.Float" { - try testing.expect(f16 == @Type(.{ .Float = .{ .bits = 16 } })); - try testing.expect(f32 == @Type(.{ .Float = .{ .bits = 32 } })); - try testing.expect(f64 == @Type(.{ .Float = .{ .bits = 64 } })); - try testing.expect(f80 == @Type(.{ .Float = .{ .bits = 80 } })); - try testing.expect(f128 == @Type(.{ .Float = .{ .bits = 128 } })); + try testing.expect(f16 == @Type(.{ .float = .{ .bits = 16 } })); + try testing.expect(f32 == @Type(.{ .float = .{ .bits = 32 } })); + try testing.expect(f64 == @Type(.{ .float = .{ .bits = 64 } })); + try testing.expect(f80 == @Type(.{ .float = .{ .bits = 80 } })); + try testing.expect(f128 == @Type(.{ .float = .{ .bits = 128 } })); try testTypes(&[_]type{ f16, f32, f64, f80, f128 }); } test "Type.Array" { try testing.expect([123]u8 == @Type(.{ - .Array = .{ + .array = .{ .len = 123, .child = u8, .sentinel = null, }, })); try testing.expect([2]u32 == @Type(.{ - .Array = .{ + .array = .{ .len = 2, .child = u32, .sentinel = null, }, })); try testing.expect([2:0]u32 == @Type(.{ - .Array = .{ + .array = .{ .len = 2, .child = u32, .sentinel = &@as(u32, 0), @@ -140,7 +140,7 @@ test "Type.Array" { test "@Type create slice with null sentinel" { const Slice = @Type(.{ - .Pointer = .{ + .pointer = .{ .size = .Slice, .is_const = true, .is_volatile = false, @@ -205,7 +205,7 @@ test "Type.Opaque" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const Opaque = @Type(.{ - .Opaque = .{ + .@"opaque" = .{ .decls = &.{}, }, }); @@ -213,7 +213,7 @@ test "Type.Opaque" { try testing.expectEqualSlices( Type.Declaration, &.{}, - @typeInfo(Opaque).Opaque.decls, + @typeInfo(Opaque).@"opaque".decls, ); } @@ -246,7 +246,7 @@ fn add(a: i32, b: i32) i32 { } test "Type.ErrorSet" { - try testing.expect(@Type(.{ .ErrorSet = null }) == anyerror); + try testing.expect(@Type(.{ .error_set = null }) == anyerror); // error sets don't compare equal so just check if they compile inline for (.{ error{}, error{A}, error{ A, B, C } }) |T| { @@ -262,7 +262,7 @@ test "Type.Struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const A = @Type(@typeInfo(struct { x: u8, y: u32 })); - const infoA = @typeInfo(A).Struct; + const infoA = @typeInfo(A).@"struct"; try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); try testing.expectEqual(u8, infoA.fields[0].type); @@ -280,7 +280,7 @@ test "Type.Struct" { try testing.expectEqual(@as(u32, 2), a.y); const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 })); - const infoB = @typeInfo(B).Struct; + const infoB = @typeInfo(B).@"struct"; try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); try testing.expectEqual(u8, infoB.fields[0].type); @@ -292,7 +292,7 @@ test "Type.Struct" { try testing.expectEqual(@as(bool, false), infoB.is_tuple); const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 })); - const infoC = @typeInfo(C).Struct; + const infoC = @typeInfo(C).@"struct"; try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); try testing.expectEqual(u8, infoC.fields[0].type); @@ -305,7 +305,7 @@ test "Type.Struct" { // anon structs const D = @Type(@typeInfo(@TypeOf(.{ .x = 3, .y = 5 }))); - const infoD = @typeInfo(D).Struct; + const infoD = @typeInfo(D).@"struct"; try testing.expectEqual(Type.ContainerLayout.auto, infoD.layout); try testing.expectEqualSlices(u8, "x", infoD.fields[0].name); try testing.expectEqual(comptime_int, infoD.fields[0].type); @@ -318,7 +318,7 @@ test "Type.Struct" { // tuples const E = @Type(@typeInfo(@TypeOf(.{ 1, 2 }))); - const infoE = @typeInfo(E).Struct; + const infoE = @typeInfo(E).@"struct"; try testing.expectEqual(Type.ContainerLayout.auto, infoE.layout); try testing.expectEqualSlices(u8, "0", infoE.fields[0].name); try testing.expectEqual(comptime_int, infoE.fields[0].type); @@ -331,14 +331,14 @@ test "Type.Struct" { // empty struct const F = @Type(@typeInfo(struct {})); - const infoF = @typeInfo(F).Struct; + const infoF = @typeInfo(F).@"struct"; try testing.expectEqual(Type.ContainerLayout.auto, infoF.layout); try testing.expect(infoF.fields.len == 0); try testing.expectEqual(@as(bool, false), infoF.is_tuple); // empty tuple const G = @Type(@typeInfo(@TypeOf(.{}))); - const infoG = @typeInfo(G).Struct; + const infoG = @typeInfo(G).@"struct"; try testing.expectEqual(Type.ContainerLayout.auto, infoG.layout); try testing.expect(infoG.fields.len == 0); try testing.expectEqual(@as(bool, true), infoG.is_tuple); @@ -349,7 +349,7 @@ test "Type.Enum" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO const Foo = @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = u8, .fields = &.{ .{ .name = "a", .value = 1 }, @@ -359,11 +359,11 @@ test "Type.Enum" { .is_exhaustive = true, }, }); - try testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive); + try testing.expectEqual(true, @typeInfo(Foo).@"enum".is_exhaustive); try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a)); try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b)); const Bar = @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = u32, .fields = &.{ .{ .name = "a", .value = 1 }, @@ -373,7 +373,7 @@ test "Type.Enum" { .is_exhaustive = false, }, }); - try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive); + try testing.expectEqual(false, @typeInfo(Bar).@"enum".is_exhaustive); try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a)); try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b)); try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6)))); @@ -385,7 +385,7 @@ test "Type.Union" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const Untagged = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .@"extern", .tag_type = null, .fields = &.{ @@ -401,7 +401,7 @@ test "Type.Union" { try testing.expectEqual(@as(i32, 3), untagged.int); const PackedUntagged = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .@"packed", .tag_type = null, .fields = &.{ @@ -417,7 +417,7 @@ test "Type.Union" { try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); const Tag = @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = u1, .fields = &.{ .{ .name = "signed", .value = 0 }, @@ -428,7 +428,7 @@ test "Type.Union" { }, }); const Tagged = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = Tag, .fields = &.{ @@ -446,7 +446,7 @@ test "Type.Union" { test "Type.Union from Type.Enum" { const Tag = @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = u0, .fields = &.{ .{ .name = "working_as_expected", .value = 0 }, @@ -456,7 +456,7 @@ test "Type.Union from Type.Enum" { }, }); const T = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = Tag, .fields = &.{ @@ -465,13 +465,13 @@ test "Type.Union from Type.Enum" { .decls = &.{}, }, }); - _ = @typeInfo(T).Union; + _ = @typeInfo(T).@"union"; } test "Type.Union from regular enum" { const E = enum { working_as_expected }; const T = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = E, .fields = &.{ @@ -480,13 +480,13 @@ test "Type.Union from regular enum" { .decls = &.{}, }, }); - _ = @typeInfo(T).Union; + _ = @typeInfo(T).@"union"; } test "Type.Union from empty regular enum" { const E = enum {}; const U = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = E, .fields = &.{}, @@ -498,7 +498,7 @@ test "Type.Union from empty regular enum" { test "Type.Union from empty Type.Enum" { const E = @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = u0, .fields = &.{}, .decls = &.{}, @@ -506,7 +506,7 @@ test "Type.Union from empty Type.Enum" { }, }); const U = @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = E, .fields = &.{}, @@ -525,7 +525,7 @@ test "Type.Fn" { const T = fn (c_int, some_ptr) callconv(.C) void; { - const fn_info = std.builtin.Type{ .Fn = .{ + const fn_info = std.builtin.Type{ .@"fn" = .{ .calling_convention = .C, .is_generic = false, .is_var_args = false, @@ -551,7 +551,7 @@ test "reified struct field name from optional payload" { comptime { const m_name: ?[1:0]u8 = "a".*; if (m_name) |*name| { - const T = @Type(.{ .Struct = .{ + const T = @Type(.{ .@"struct" = .{ .layout = .auto, .fields = &.{.{ .name = name, @@ -573,7 +573,7 @@ test "reified union uses @alignOf" { const S = struct { fn CreateUnion(comptime T: type) type { return @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = null, .fields = &[_]std.builtin.Type.UnionField{ @@ -595,7 +595,7 @@ test "reified struct uses @alignOf" { const S = struct { fn NamespacedGlobals(comptime modules: anytype) type { return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = &.{ @@ -627,7 +627,7 @@ test "reified error set initialized with field pointer" { }, }; const Foo = @Type(.{ - .ErrorSet = &info.args, + .error_set = &info.args, }); }; try testing.expect(S.Foo == error{bar}); @@ -640,7 +640,7 @@ test "reified function type params initialized with field pointer" { }, }; const Bar = @Type(.{ - .Fn = .{ + .@"fn" = .{ .calling_convention = .Unspecified, .is_generic = false, .is_var_args = false, @@ -649,14 +649,14 @@ test "reified function type params initialized with field pointer" { }, }); }; - try testing.expect(@typeInfo(S.Bar) == .Fn); + try testing.expect(@typeInfo(S.Bar) == .@"fn"); } test "empty struct assigned to reified struct field" { const S = struct { fn NamespacedComponents(comptime modules: anytype) type { return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = &.{.{ @@ -689,7 +689,7 @@ test "@Type should resolve its children types" { const dense = enum(u2) { a, b, c, d }; comptime var sparse_info = @typeInfo(anyerror!sparse); - sparse_info.ErrorUnion.payload = dense; + sparse_info.error_union.payload = dense; const B = @Type(sparse_info); try testing.expectEqual(anyerror!dense, B); } @@ -718,7 +718,7 @@ test "struct field names sliced at comptime from larger string" { } const T = @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -726,7 +726,7 @@ test "struct field names sliced at comptime from larger string" { }, }); - const gen_fields = @typeInfo(T).Struct.fields; + const gen_fields = @typeInfo(T).@"struct".fields; try testing.expectEqual(3, gen_fields.len); try testing.expectEqualStrings("f1", gen_fields[0].name); try testing.expectEqualStrings("f2", gen_fields[1].name); @@ -737,9 +737,9 @@ test "struct field names sliced at comptime from larger string" { test "matching captures causes opaque equivalence" { const S = struct { fn UnsignedId(comptime I: type) type { - const U = @Type(.{ .Int = .{ + const U = @Type(.{ .int = .{ .signedness = .unsigned, - .bits = @typeInfo(I).Int.bits, + .bits = @typeInfo(I).int.bits, } }); return opaque { fn id(x: U) U { @@ -765,7 +765,7 @@ test "reify enum where fields refers to part of array" { .{ .name = "bar", .value = 1 }, undefined, }; - const E = @Type(.{ .Enum = .{ + const E = @Type(.{ .@"enum" = .{ .tag_type = u8, .fields = fields[0..2], .decls = &.{}, |
