mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
behavior: small tweaks for new semantics
This commit is contained in:
parent
9070e84c2a
commit
6fdefef052
2 changed files with 32 additions and 7 deletions
|
|
@ -30,13 +30,41 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
|
|||
var runtime_index: usize = 1;
|
||||
_ = &runtime_index;
|
||||
const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
|
||||
try expect(@TypeOf(slice) == []u8);
|
||||
try expect(@TypeOf(slice) == []align(1) u8);
|
||||
try expect(slice.len == 0);
|
||||
try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0);
|
||||
}
|
||||
|
||||
test "default alignment allows unspecified in type syntax" {
|
||||
try expect(*u32 == *align(@alignOf(u32)) u32);
|
||||
test "implicitly-aligned pointer is coercible to equivalent explicitly-aligned pointer" {
|
||||
const A = *u32;
|
||||
const B = *align(@alignOf(u32)) u32;
|
||||
|
||||
comptime assert(A != B);
|
||||
|
||||
const static = struct {
|
||||
fn doTheTest() !void {
|
||||
var buf: u32 = 123;
|
||||
|
||||
const ptr: A = &buf;
|
||||
const coerced_ptr: B = ptr;
|
||||
|
||||
try expect(ptr == coerced_ptr);
|
||||
try expect(ptr.* == 123);
|
||||
try expect(coerced_ptr.* == 123);
|
||||
|
||||
const ptr_ptr: *const A = &ptr;
|
||||
const coerced_ptr_ptr: *const B = ptr_ptr;
|
||||
|
||||
try expect(ptr_ptr == coerced_ptr_ptr);
|
||||
try expect(ptr_ptr.* == &buf);
|
||||
try expect(coerced_ptr_ptr.* == &buf);
|
||||
try expect(ptr_ptr.*.* == 123);
|
||||
try expect(coerced_ptr_ptr.*.* == 123);
|
||||
}
|
||||
};
|
||||
|
||||
try static.doTheTest();
|
||||
try comptime static.doTheTest();
|
||||
}
|
||||
|
||||
test "implicitly decreasing pointer alignment" {
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ test "generic instantiation of tagged union with only one field" {
|
|||
try expect(S.foo(.{ .s = "ab" }) == 2);
|
||||
}
|
||||
|
||||
test "nested generic function" {
|
||||
test "generic parameter type is function type" {
|
||||
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
||||
|
||||
const S = struct {
|
||||
|
|
@ -349,10 +349,7 @@ test "nested generic function" {
|
|||
fn bar(a: u32) anyerror!void {
|
||||
try expect(a == 123);
|
||||
}
|
||||
|
||||
fn g(_: *const fn (anytype) void) void {}
|
||||
};
|
||||
try expect(@typeInfo(@TypeOf(S.g)).@"fn".is_generic);
|
||||
try S.foo(u32, S.bar, 123);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue