behavior: avoid field/decl name conflicts

This commit is contained in:
mlugg 2024-08-28 19:37:28 +01:00
parent 605f2a0978
commit c3fb30803f
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
4 changed files with 13 additions and 25 deletions

View File

@ -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" {

View File

@ -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,

View File

@ -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" {

View File

@ -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" {