zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c3fb30803f4fbe62abb4bfad348c585e9ab80234 (tree)
parent 605f2a0978c3ae262e224ff01d163d412a64c284
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed, 28 Aug 2024 19:37:28 +0100

behavior: avoid field/decl name conflicts

Diffstat:
Mtest/behavior/call.zig | 8++++----
Mtest/behavior/packed-union.zig | 4++--
Mtest/behavior/struct.zig | 6+++---
Mtest/behavior/union.zig | 20++++----------------
4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/test/behavior/call.zig b/test/behavior/call.zig @@ -549,7 +549,7 @@ test "call function pointer in comptime field" { auto: [max_len]u8 = undefined, offset: u64 = 0, - comptime capacity: *const fn () u64 = capacity, + comptime capacityFn: *const fn () u64 = capacity, const max_len: u64 = 32; @@ -558,9 +558,9 @@ test "call function pointer in comptime field" { } }; - const a: Auto = .{ .offset = 16, .capacity = Auto.capacity }; - try std.testing.expect(a.capacity() == 32); - try std.testing.expect((a.capacity)() == 32); + const a: Auto = .{ .offset = 16, .capacityFn = Auto.capacity }; + try std.testing.expect(a.capacityFn() == 32); + try std.testing.expect((a.capacityFn)() == 32); } test "generic function pointer can be called" { diff --git a/test/behavior/packed-union.zig b/test/behavior/packed-union.zig @@ -149,12 +149,12 @@ test "packed union initialized with a runtime value" { value: u63, fields: Fields, - fn value() i64 { + fn getValue() i64 { return 1341; } }; - const timestamp: i64 = ID.value(); + const timestamp: i64 = ID.getValue(); const id = ID{ .fields = Fields{ .timestamp = @as(u50, @intCast(timestamp)), .random_bits = 420, diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig @@ -1529,15 +1529,15 @@ test "function pointer in struct returns the struct" { const A = struct { const A = @This(); - f: *const fn () A, + ptr: *const fn () A, fn f() A { - return .{ .f = f }; + return .{ .ptr = f }; } }; var a = A.f(); _ = &a; - try expect(a.f == A.f); + try expect(a.ptr == A.f); } test "no dependency loop on optional field wrapped in generic function" { diff --git a/test/behavior/union.zig b/test/behavior/union.zig @@ -155,18 +155,6 @@ test "unions embedded in aggregate types" { } } -test "access a member of tagged union with conflicting enum tag name" { - const Bar = union(enum) { - A: A, - B: B, - - const A = u8; - const B = void; - }; - - comptime assert(Bar.A == u8); -} - test "constant tagged union with payload" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; @@ -1417,10 +1405,10 @@ test "union field ptr - zero sized payload" { const U = union { foo: void, bar: void, - fn bar(_: *void) void {} + fn qux(_: *void) void {} }; var u: U = .{ .foo = {} }; - U.bar(&u.foo); + U.qux(&u.foo); } test "union field ptr - zero sized field" { @@ -1431,10 +1419,10 @@ test "union field ptr - zero sized field" { const U = union { foo: void, bar: u32, - fn bar(_: *void) void {} + fn qux(_: *void) void {} }; var u: U = .{ .foo = {} }; - U.bar(&u.foo); + U.qux(&u.foo); } test "packed union in packed struct" {