mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
behavior: avoid field/decl name conflicts
This commit is contained in:
parent
605f2a0978
commit
c3fb30803f
4 changed files with 13 additions and 25 deletions
|
|
@ -549,7 +549,7 @@ test "call function pointer in comptime field" {
|
||||||
auto: [max_len]u8 = undefined,
|
auto: [max_len]u8 = undefined,
|
||||||
offset: u64 = 0,
|
offset: u64 = 0,
|
||||||
|
|
||||||
comptime capacity: *const fn () u64 = capacity,
|
comptime capacityFn: *const fn () u64 = capacity,
|
||||||
|
|
||||||
const max_len: u64 = 32;
|
const max_len: u64 = 32;
|
||||||
|
|
||||||
|
|
@ -558,9 +558,9 @@ test "call function pointer in comptime field" {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const a: Auto = .{ .offset = 16, .capacity = Auto.capacity };
|
const a: Auto = .{ .offset = 16, .capacityFn = Auto.capacity };
|
||||||
try std.testing.expect(a.capacity() == 32);
|
try std.testing.expect(a.capacityFn() == 32);
|
||||||
try std.testing.expect((a.capacity)() == 32);
|
try std.testing.expect((a.capacityFn)() == 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "generic function pointer can be called" {
|
test "generic function pointer can be called" {
|
||||||
|
|
|
||||||
|
|
@ -149,12 +149,12 @@ test "packed union initialized with a runtime value" {
|
||||||
value: u63,
|
value: u63,
|
||||||
fields: Fields,
|
fields: Fields,
|
||||||
|
|
||||||
fn value() i64 {
|
fn getValue() i64 {
|
||||||
return 1341;
|
return 1341;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const timestamp: i64 = ID.value();
|
const timestamp: i64 = ID.getValue();
|
||||||
const id = ID{ .fields = Fields{
|
const id = ID{ .fields = Fields{
|
||||||
.timestamp = @as(u50, @intCast(timestamp)),
|
.timestamp = @as(u50, @intCast(timestamp)),
|
||||||
.random_bits = 420,
|
.random_bits = 420,
|
||||||
|
|
|
||||||
|
|
@ -1529,15 +1529,15 @@ test "function pointer in struct returns the struct" {
|
||||||
|
|
||||||
const A = struct {
|
const A = struct {
|
||||||
const A = @This();
|
const A = @This();
|
||||||
f: *const fn () A,
|
ptr: *const fn () A,
|
||||||
|
|
||||||
fn f() A {
|
fn f() A {
|
||||||
return .{ .f = f };
|
return .{ .ptr = f };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var a = A.f();
|
var a = A.f();
|
||||||
_ = &a;
|
_ = &a;
|
||||||
try expect(a.f == A.f);
|
try expect(a.ptr == A.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "no dependency loop on optional field wrapped in generic function" {
|
test "no dependency loop on optional field wrapped in generic function" {
|
||||||
|
|
|
||||||
|
|
@ -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" {
|
test "constant tagged union with payload" {
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||||
if (builtin.zig_backend == .stage2_aarch64) 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 {
|
const U = union {
|
||||||
foo: void,
|
foo: void,
|
||||||
bar: void,
|
bar: void,
|
||||||
fn bar(_: *void) void {}
|
fn qux(_: *void) void {}
|
||||||
};
|
};
|
||||||
var u: U = .{ .foo = {} };
|
var u: U = .{ .foo = {} };
|
||||||
U.bar(&u.foo);
|
U.qux(&u.foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "union field ptr - zero sized field" {
|
test "union field ptr - zero sized field" {
|
||||||
|
|
@ -1431,10 +1419,10 @@ test "union field ptr - zero sized field" {
|
||||||
const U = union {
|
const U = union {
|
||||||
foo: void,
|
foo: void,
|
||||||
bar: u32,
|
bar: u32,
|
||||||
fn bar(_: *void) void {}
|
fn qux(_: *void) void {}
|
||||||
};
|
};
|
||||||
var u: U = .{ .foo = {} };
|
var u: U = .{ .foo = {} };
|
||||||
U.bar(&u.foo);
|
U.qux(&u.foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "packed union in packed struct" {
|
test "packed union in packed struct" {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue