mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 03:24:46 +01:00
behavior: misc fixes
They compile now! They don't *pass*, but they *compile*!
This commit is contained in:
parent
9766641ff3
commit
1e682fed7b
6 changed files with 26 additions and 30 deletions
|
|
@ -307,11 +307,15 @@ test "runtime-known array index has best alignment possible" {
|
|||
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
||||
|
||||
// take full advantage of over-alignment
|
||||
var array align(4) = [_]u8{ 1, 2, 3, 4 };
|
||||
var array align(4) = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
comptime assert(@TypeOf(&array[0]) == *align(4) u8);
|
||||
comptime assert(@TypeOf(&array[1]) == *u8);
|
||||
comptime assert(@TypeOf(&array[1]) == *align(1) u8);
|
||||
comptime assert(@TypeOf(&array[2]) == *align(2) u8);
|
||||
comptime assert(@TypeOf(&array[3]) == *u8);
|
||||
comptime assert(@TypeOf(&array[3]) == *align(1) u8);
|
||||
comptime assert(@TypeOf(&array[4]) == *align(4) u8);
|
||||
comptime assert(@TypeOf(&array[5]) == *align(1) u8);
|
||||
comptime assert(@TypeOf(&array[6]) == *align(2) u8);
|
||||
comptime assert(@TypeOf(&array[7]) == *align(1) u8);
|
||||
|
||||
// because align is too small but we still figure out to use 2
|
||||
var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
|
||||
|
|
@ -332,10 +336,14 @@ test "runtime-known array index has best alignment possible" {
|
|||
try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
|
||||
|
||||
// has to use ABI alignment because index known at runtime only
|
||||
try testIndex2(&array, 0, *u8);
|
||||
try testIndex2(&array, 1, *u8);
|
||||
try testIndex2(&array, 2, *u8);
|
||||
try testIndex2(&array, 3, *u8);
|
||||
try testIndex2(&array, 0, *align(1) u8);
|
||||
try testIndex2(&array, 1, *align(1) u8);
|
||||
try testIndex2(&array, 2, *align(1) u8);
|
||||
try testIndex2(&array, 3, *align(1) u8);
|
||||
try testIndex2(&array, 4, *align(1) u8);
|
||||
try testIndex2(&array, 5, *align(1) u8);
|
||||
try testIndex2(&array, 6, *align(1) u8);
|
||||
try testIndex2(&array, 7, *align(1) u8);
|
||||
}
|
||||
fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
|
||||
comptime assert(@TypeOf(&smaller[index]) == T);
|
||||
|
|
|
|||
|
|
@ -350,9 +350,6 @@ test "comptime @bitCast packed struct to int and back" {
|
|||
iint_neg2: i3 = -2,
|
||||
float: f32 = 3.14,
|
||||
@"enum": enum(u2) { A, B = 1, C, D } = .B,
|
||||
vectorb: @Vector(3, bool) = .{ true, false, true },
|
||||
vectori: @Vector(2, u8) = .{ 127, 42 },
|
||||
vectorf: @Vector(2, f16) = .{ 3.14, 2.71 },
|
||||
};
|
||||
const Int = @typeInfo(S).@"struct".backing_integer.?;
|
||||
|
||||
|
|
|
|||
|
|
@ -551,19 +551,18 @@ test "generic function pointer can be called" {
|
|||
|
||||
test "value returned from comptime function is comptime known" {
|
||||
const S = struct {
|
||||
fn fields(comptime T: type) switch (@typeInfo(T)) {
|
||||
.@"struct" => []const std.builtin.Type.StructField,
|
||||
fn fieldCount(comptime T: type) switch (@typeInfo(T)) {
|
||||
.@"struct" => comptime_int,
|
||||
else => unreachable,
|
||||
} {
|
||||
return switch (@typeInfo(T)) {
|
||||
.@"struct" => |info| info.fields,
|
||||
.@"struct" => |info| info.fields.len,
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
};
|
||||
const fields_list = S.fields(@TypeOf(.{}));
|
||||
if (fields_list.len != 0)
|
||||
@compileError("Argument count mismatch");
|
||||
const fields_len = S.fieldCount(@TypeOf(.{}));
|
||||
comptime assert(fields_len == 0);
|
||||
}
|
||||
|
||||
test "registers get overwritten when ignoring return" {
|
||||
|
|
|
|||
|
|
@ -719,13 +719,6 @@ fn testVarInsideInlineLoop(args: anytype) !void {
|
|||
}
|
||||
}
|
||||
|
||||
test "*align(1) u16 is the same as *align(1:0:2) u16" {
|
||||
comptime {
|
||||
try expect(*align(1:0:2) u16 == *align(1) u16);
|
||||
try expect(*align(2:0:2) u16 == *u16);
|
||||
}
|
||||
}
|
||||
|
||||
test "array concatenation of function calls" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
|
|
|||
|
|
@ -820,7 +820,7 @@ test "packed struct passed to callconv(.c) function" {
|
|||
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
|
||||
|
||||
const S = struct {
|
||||
const Packed = packed struct {
|
||||
const Packed = packed struct(u64) {
|
||||
a: u16,
|
||||
b: bool = true,
|
||||
c: bool = true,
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ test "switch prong pointer capture alignment" {
|
|||
}
|
||||
|
||||
switch (u) {
|
||||
.a, .c => |*p| comptime assert(@TypeOf(p) == *const u8),
|
||||
.a, .c => |*p| comptime assert(@TypeOf(p) == *align(1) const u8),
|
||||
.b => |*p| {
|
||||
_ = p;
|
||||
return error.TestFailed;
|
||||
|
|
@ -1141,24 +1141,23 @@ test "decl literals as switch cases" {
|
|||
try comptime E.doTheTest(.foo);
|
||||
}
|
||||
|
||||
// TODO audit after #15909 and/or #19855 are decided/implemented
|
||||
// TODO audit after #15909 and/or #19855 are decided/implemented.
|
||||
// When we do that, consider adding an 'error{}' case if possible.
|
||||
test "switch with uninstantiable union fields" {
|
||||
const U = union(enum) {
|
||||
ok: void,
|
||||
a: noreturn,
|
||||
b: noreturn,
|
||||
c: error{},
|
||||
|
||||
fn doTheTest(u: @This()) void {
|
||||
switch (u) {
|
||||
.ok => {},
|
||||
.a => comptime unreachable,
|
||||
.b => comptime unreachable,
|
||||
.c => comptime unreachable,
|
||||
}
|
||||
switch (u) {
|
||||
.ok => {},
|
||||
.a, .b, .c => comptime unreachable,
|
||||
.a, .b => comptime unreachable,
|
||||
}
|
||||
switch (u) {
|
||||
.ok => {},
|
||||
|
|
@ -1166,7 +1165,7 @@ test "switch with uninstantiable union fields" {
|
|||
}
|
||||
switch (u) {
|
||||
.a => comptime unreachable,
|
||||
.ok, .b, .c => {},
|
||||
.ok, .b => {},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue