From c3fb30803f4fbe62abb4bfad348c585e9ab80234 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 28 Aug 2024 19:37:28 +0100 Subject: [PATCH] behavior: avoid field/decl name conflicts --- test/behavior/call.zig | 8 ++++---- test/behavior/packed-union.zig | 4 ++-- test/behavior/struct.zig | 6 +++--- test/behavior/union.zig | 20 ++++---------------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 3995a24fae..5b94a4b07d 100644 --- 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 index aa4f98b783..701c0484a4 100644 --- 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 index ff70c14505..44f035f46f 100644 --- 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 index 13d8862dea..a952e9b9d3 100644 --- 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" {