Skip to content

Commit

Permalink
behavior: avoid field/decl name conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mlugg committed Aug 28, 2024
1 parent 0a8e1c9 commit 662daa8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
8 changes: 4 additions & 4 deletions test/behavior/call.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions test/behavior/packed-union.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test/behavior/struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
20 changes: 4 additions & 16 deletions test/behavior/union.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down

0 comments on commit 662daa8

Please sign in to comment.