Skip to content

Commit d41fdb9

Browse files
committed
behavior: avoid field/decl name conflicts
1 parent 123c235 commit d41fdb9

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

test/behavior/call.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test "call function pointer in comptime field" {
549549
auto: [max_len]u8 = undefined,
550550
offset: u64 = 0,
551551

552-
comptime capacity: *const fn () u64 = capacity,
552+
comptime capacityFn: *const fn () u64 = capacity,
553553

554554
const max_len: u64 = 32;
555555

@@ -558,9 +558,9 @@ test "call function pointer in comptime field" {
558558
}
559559
};
560560

561-
const a: Auto = .{ .offset = 16, .capacity = Auto.capacity };
562-
try std.testing.expect(a.capacity() == 32);
563-
try std.testing.expect((a.capacity)() == 32);
561+
const a: Auto = .{ .offset = 16, .capacityFn = Auto.capacity };
562+
try std.testing.expect(a.capacityFn() == 32);
563+
try std.testing.expect((a.capacityFn)() == 32);
564564
}
565565

566566
test "generic function pointer can be called" {

test/behavior/packed-union.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ test "packed union initialized with a runtime value" {
149149
value: u63,
150150
fields: Fields,
151151

152-
fn value() i64 {
152+
fn getValue() i64 {
153153
return 1341;
154154
}
155155
};
156156

157-
const timestamp: i64 = ID.value();
157+
const timestamp: i64 = ID.getValue();
158158
const id = ID{ .fields = Fields{
159159
.timestamp = @as(u50, @intCast(timestamp)),
160160
.random_bits = 420,

test/behavior/struct.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,15 +1529,15 @@ test "function pointer in struct returns the struct" {
15291529

15301530
const A = struct {
15311531
const A = @This();
1532-
f: *const fn () A,
1532+
ptr: *const fn () A,
15331533

15341534
fn f() A {
1535-
return .{ .f = f };
1535+
return .{ .ptr = f };
15361536
}
15371537
};
15381538
var a = A.f();
15391539
_ = &a;
1540-
try expect(a.f == A.f);
1540+
try expect(a.ptr == A.f);
15411541
}
15421542

15431543
test "no dependency loop on optional field wrapped in generic function" {

test/behavior/union.zig

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,6 @@ test "unions embedded in aggregate types" {
155155
}
156156
}
157157

158-
test "access a member of tagged union with conflicting enum tag name" {
159-
const Bar = union(enum) {
160-
A: A,
161-
B: B,
162-
163-
const A = u8;
164-
const B = void;
165-
};
166-
167-
comptime assert(Bar.A == u8);
168-
}
169-
170158
test "constant tagged union with payload" {
171159
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
172160
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
@@ -1417,10 +1405,10 @@ test "union field ptr - zero sized payload" {
14171405
const U = union {
14181406
foo: void,
14191407
bar: void,
1420-
fn bar(_: *void) void {}
1408+
fn qux(_: *void) void {}
14211409
};
14221410
var u: U = .{ .foo = {} };
1423-
U.bar(&u.foo);
1411+
U.qux(&u.foo);
14241412
}
14251413

14261414
test "union field ptr - zero sized field" {
@@ -1431,10 +1419,10 @@ test "union field ptr - zero sized field" {
14311419
const U = union {
14321420
foo: void,
14331421
bar: u32,
1434-
fn bar(_: *void) void {}
1422+
fn qux(_: *void) void {}
14351423
};
14361424
var u: U = .{ .foo = {} };
1437-
U.bar(&u.foo);
1425+
U.qux(&u.foo);
14381426
}
14391427

14401428
test "packed union in packed struct" {

0 commit comments

Comments
 (0)