Commit 804cee3b93
Changed files (172)
test
behavior
bugs
cases
test/behavior/bugs/10138.zig
@@ -1,34 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test "registers get overwritten when ignoring return" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest;
-
- const fd = open();
- _ = write(fd, "a", 1);
- _ = close(fd);
-}
-
-fn open() usize {
- return 42;
-}
-
-fn write(fd: usize, a: [*]const u8, len: usize) usize {
- return syscall4(.WRITE, fd, @intFromPtr(a), len);
-}
-
-fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
- _ = n;
- _ = a;
- _ = b;
- _ = c;
- return 23;
-}
-
-fn close(fd: usize) usize {
- if (fd != 42)
- unreachable;
- return 0;
-}
test/behavior/bugs/10147.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-
-test "test calling @clz on both vector and scalar inputs" {
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var x: u32 = 0x1;
- _ = &x;
- var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
- _ = &y;
- const a = @clz(x);
- const b = @clz(y);
- try std.testing.expectEqual(@as(u6, 31), a);
- try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
-}
test/behavior/bugs/1025.zig
@@ -1,14 +0,0 @@
-const builtin = @import("builtin");
-
-const A = struct {
- B: type,
-};
-
-fn getA() A {
- return A{ .B = u8 };
-}
-
-test "bug 1025" {
- const a = getA();
- try @import("std").testing.expect(a.B == u8);
-}
test/behavior/bugs/10684.zig
@@ -1,17 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expectEqualStrings = std.testing.expectEqualStrings;
-
-test "slicing slices" {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const foo = "1234";
- const bar = foo[0..4];
- try expectEqualStrings("1234", bar);
- try expectEqualStrings("2", bar[1..2]);
- try expectEqualStrings("3", bar[2..3]);
- try expectEqualStrings("4", bar[3..4]);
- try expectEqualStrings("34", bar[2..4]);
-}
test/behavior/bugs/1076.zig
@@ -1,27 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const mem = std.mem;
-const expect = std.testing.expect;
-
-test "comptime code should not modify constant data" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try testCastPtrOfArrayToSliceAndPtr();
- try comptime testCastPtrOfArrayToSliceAndPtr();
-}
-
-fn testCastPtrOfArrayToSliceAndPtr() !void {
- {
- var array = "aoeu".*;
- const x: [*]u8 = &array;
- x[0] += 1;
- try expect(mem.eql(u8, array[0..], "boeu"));
- }
- {
- var array: [4]u8 = "aoeu".*;
- const x: [*]u8 = &array;
- x[0] += 1;
- try expect(mem.eql(u8, array[0..], "boeu"));
- }
-}
test/behavior/bugs/10970.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-
-fn retOpt() ?u32 {
- return null;
-}
-test "breaking from a loop in an if statement" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var cond = true;
- _ = &cond;
- const opt = while (cond) {
- if (retOpt()) |opt| {
- break opt;
- }
- break 1;
- } else 2;
- _ = opt;
-}
test/behavior/bugs/11046.zig
@@ -1,22 +0,0 @@
-const builtin = @import("builtin");
-
-fn foo() !void {
- var a = true;
- _ = &a;
- if (a) return error.Foo;
- return error.Bar;
-}
-fn bar() !void {
- try foo();
-}
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- bar() catch |err| switch (err) {
- error.Foo => {}, // error: expected (inferred error set of bar), found error{Foo}
- error.Bar => {},
- };
-}
test/behavior/bugs/11100.zig
@@ -1,13 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-pub fn do() bool {
- inline for (.{"a"}) |_| {
- if (true) return false;
- }
- return true;
-}
-
-test "bug" {
- try std.testing.expect(!do());
-}
test/behavior/bugs/11139.zig
@@ -1,26 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-test "store array of array of structs at comptime" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try expect(storeArrayOfArrayOfStructs() == 15);
- try comptime expect(storeArrayOfArrayOfStructs() == 15);
-}
-
-fn storeArrayOfArrayOfStructs() u8 {
- const S = struct {
- x: u8,
- };
-
- var cases = [_][1]S{
- [_]S{
- S{ .x = 15 },
- },
- };
- _ = &cases;
- return cases[0][0].x;
-}
test/behavior/bugs/11159.zig
@@ -1,19 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
- var a: T = .{ 0, 0 };
- _ = &a;
-}
-
-test {
- const S = struct {
- comptime x: i32 = 0,
- comptime y: u32 = 0,
- };
- var a: S = .{};
- _ = &a;
- var b = S{};
- _ = &b;
-}
test/behavior/bugs/11162.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-test "aggregate initializers should allow initializing comptime fields, verifying equality" {
- if (true) return error.SkipZigTest; // TODO
-
- var x: u32 = 15;
- _ = &x;
- const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
- const a: T = .{ -1234, 5678, x + 1 };
-
- try expect(a[0] == -1234);
- try expect(a[1] == 5678);
- try expect(a[2] == 16);
-}
test/behavior/bugs/11165.zig
@@ -1,44 +0,0 @@
-const builtin = @import("builtin");
-
-test "bytes" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const S = struct {
- a: u32,
- c: [5]u8,
- };
-
- const U = union {
- s: S,
- };
-
- const s_1 = S{
- .a = undefined,
- .c = "12345".*, // this caused problems
- };
-
- var u_2 = U{ .s = s_1 };
- _ = &u_2;
-}
-
-test "aggregate" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const S = struct {
- a: u32,
- c: [5]u8,
- };
-
- const U = union {
- s: S,
- };
-
- const c = [5:0]u8{ 1, 2, 3, 4, 5 };
- const s_1 = S{
- .a = undefined,
- .c = c, // this caused problems
- };
-
- var u_2 = U{ .s = s_1 };
- _ = &u_2;
-}
test/behavior/bugs/11179.zig
@@ -1,19 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const Type = std.builtin.Type;
-
-test "Tuple" {
- const fields_list = fields(@TypeOf(.{}));
- if (fields_list.len != 0)
- @compileError("Argument count mismatch");
-}
-
-pub fn fields(comptime T: type) switch (@typeInfo(T)) {
- .Struct => []const Type.StructField,
- else => unreachable,
-} {
- return switch (@typeInfo(T)) {
- .Struct => |info| info.fields,
- else => unreachable,
- };
-}
test/behavior/bugs/11181.zig
@@ -1,25 +0,0 @@
-const builtin = @import("builtin");
-
-test "const inferred array of slices" {
- const T = struct { v: bool };
-
- const decls = [_][]const T{
- &[_]T{
- .{ .v = false },
- },
- };
- _ = decls;
-}
-
-test "var inferred array of slices" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const T = struct { v: bool };
-
- var decls = [_][]const T{
- &[_]T{
- .{ .v = false },
- },
- };
- _ = &decls;
-}
test/behavior/bugs/11213.zig
@@ -1,33 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const testing = std.testing;
-
-test {
- const g: error{Test}!void = error.Test;
-
- var v: u32 = 0;
- hash(&v, g);
- try testing.expect(v == 1);
-}
-
-fn hash(v: *u32, key: anytype) void {
- const Key = @TypeOf(key);
-
- if (@typeInfo(Key) == .ErrorSet) {
- v.* += 1;
- return;
- }
-
- switch (@typeInfo(Key)) {
- .ErrorUnion => blk: {
- const payload = key catch |err| {
- hash(v, err);
- break :blk;
- };
-
- hash(v, payload);
- },
-
- else => unreachable,
- }
-}
test/behavior/bugs/11787.zig
@@ -1,19 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const testing = std.testing;
-
-test "slicing zero length array field of struct" {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const S = struct {
- a: [0]usize,
- fn foo(self: *@This(), start: usize, end: usize) []usize {
- return self.a[start..end];
- }
- };
- var s: S = undefined;
- try testing.expect(s.foo(0, 0).len == 0);
-}
test/behavior/bugs/11816.zig
@@ -1,14 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var x: u32 = 3;
- const val: usize = while (true) switch (x) {
- 1 => break 2,
- else => x -= 1,
- };
- try std.testing.expect(val == 2);
-}
test/behavior/bugs/11995.zig
@@ -1,33 +0,0 @@
-const std = @import("std");
-const testing = std.testing;
-const builtin = @import("builtin");
-
-fn wuffs_base__make_io_buffer(arg_data: wuffs_base__slice_u8, arg_meta: *wuffs_base__io_buffer_meta) callconv(.C) void {
- arg_data.ptr[0] = 'w';
- arg_meta.closed = false;
-}
-const wuffs_base__io_buffer_meta = extern struct {
- wi: usize,
- ri: usize,
- pos: u64,
- closed: bool,
-};
-const wuffs_base__slice_u8 = extern struct {
- ptr: [*c]u8,
- len: usize,
-};
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var string: [5]u8 = "hello".*;
- const arg_data = wuffs_base__slice_u8{ .ptr = @as([*c]u8, @ptrCast(&string)), .len = string.len };
- var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true };
- wuffs_base__make_io_buffer(arg_data, &arg_meta);
- try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]);
- try std.testing.expectEqual(@as(usize, 1), arg_meta.wi);
- try std.testing.expectEqual(@as(usize, 2), arg_meta.ri);
- try std.testing.expectEqual(@as(u64, 3), arg_meta.pos);
- try std.testing.expect(!arg_meta.closed);
-}
test/behavior/bugs/12000.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const T = struct {
- next: @TypeOf(null, @as(*const T, undefined)),
-};
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var t: T = .{ .next = null };
- _ = &t;
- try std.testing.expect(t.next == null);
-}
test/behavior/bugs/12003.zig
@@ -1,7 +0,0 @@
-test {
- comptime {
- const tuple_with_ptrs = .{ &0, &0 };
- const field_ptr = (&tuple_with_ptrs.@"0");
- _ = field_ptr.*;
- }
-}
test/behavior/bugs/12025.zig
@@ -1,13 +0,0 @@
-const builtin = @import("builtin");
-
-test {
- comptime var st = .{
- .foo = &1,
- .bar = &2,
- };
- _ = &st;
-
- inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
- _ = field;
- }
-}
test/behavior/bugs/12033.zig
@@ -1,13 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- const string = "Hello!\x00World!";
- try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
-
- const slice_without_sentinel: []const u8 = string[0..6];
- try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
-
- const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
- try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
-}
test/behavior/bugs/12043.zig
@@ -1,13 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-var ok = false;
-fn foo(x: anytype) void {
- ok = x;
-}
-test {
- const x = &foo;
- x(true);
- try expect(ok);
-}
test/behavior/bugs/12051.zig
@@ -1,40 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const x = X{};
- try std.testing.expectEqual(@as(u16, 0), x.y.a);
- try std.testing.expectEqual(false, x.y.b);
- try std.testing.expectEqual(Z{ .a = 0 }, x.y.c);
- try std.testing.expectEqual(Z{ .a = 0 }, x.y.d);
-}
-
-const X = struct {
- y: Y = Y.init(),
-};
-
-const Y = struct {
- a: u16,
- b: bool,
- c: Z,
- d: Z,
-
- fn init() Y {
- return .{
- .a = 0,
- .b = false,
- .c = @as(Z, @bitCast(@as(u32, 0))),
- .d = @as(Z, @bitCast(@as(u32, 0))),
- };
- }
-};
-
-const Z = packed struct {
- a: u32,
-};
test/behavior/bugs/12092.zig
@@ -1,28 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Foo = struct {
- a: Bar,
-};
-
-const Bar = struct {
- b: u32,
-};
-
-fn takeFoo(foo: *const Foo) !void {
- try std.testing.expectEqual(@as(u32, 24), foo.a.b);
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var baz: u32 = 24;
- _ = &baz;
- try takeFoo(&.{
- .a = .{
- .b = baz,
- },
- });
-}
test/behavior/bugs/12119.zig
@@ -1,15 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const u8x32 = @Vector(32, u8);
-const u32x8 = @Vector(8, u32);
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const zerox32: u8x32 = [_]u8{0} ** 32;
- const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32));
- try std.testing.expectEqual(0, @reduce(.Add, bigsum));
-}
test/behavior/bugs/12142.zig
@@ -1,36 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Holder = struct {
- array: []const u8,
-};
-
-const Test = struct {
- holders: []const Holder,
-};
-
-const Letter = enum(u8) {
- A = 0x41,
- B,
-};
-
-fn letter(e: Letter) u8 {
- return @intFromEnum(e);
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const test_struct = Test{
- .holders = &.{
- Holder{
- .array = &.{
- letter(.A),
- },
- },
- },
- };
- try std.testing.expectEqualStrings("A", test_struct.holders[0].array);
-}
test/behavior/bugs/12169.zig
@@ -1,19 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) {
- // https://github.com/ziglang/zig/issues/13782
- return error.SkipZigTest;
- }
-
- const a = @Vector(2, bool){ true, true };
- const b = @Vector(1, bool){true};
- try std.testing.expect(@reduce(.And, a));
- try std.testing.expect(@reduce(.And, b));
-}
test/behavior/bugs/12430.zig
@@ -1,11 +0,0 @@
-const std = @import("std");
-
-test {
- const T = comptime b: {
- break :b @Type(.{ .Int = .{
- .signedness = .unsigned,
- .bits = 8,
- } });
- };
- try std.testing.expect(T == u8);
-}
test/behavior/bugs/12450.zig
@@ -1,22 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-const Foo = packed struct {
- a: i32,
- b: u8,
-};
-
-var buffer: [256]u8 = undefined;
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&buffer[0])));
- try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
- try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
- try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);
-}
test/behavior/bugs/12486.zig
@@ -1,49 +0,0 @@
-const SomeEnum = union(enum) {
- EnumVariant: u8,
-};
-
-const SomeStruct = struct {
- struct_field: u8,
-};
-
-const OptEnum = struct {
- opt_enum: ?SomeEnum,
-};
-
-const ErrEnum = struct {
- err_enum: anyerror!SomeEnum,
-};
-
-const OptStruct = struct {
- opt_struct: ?SomeStruct,
-};
-
-const ErrStruct = struct {
- err_struct: anyerror!SomeStruct,
-};
-
-test {
- _ = OptEnum{
- .opt_enum = .{
- .EnumVariant = 1,
- },
- };
-
- _ = ErrEnum{
- .err_enum = .{
- .EnumVariant = 1,
- },
- };
-
- _ = OptStruct{
- .opt_struct = .{
- .struct_field = 1,
- },
- };
-
- _ = ErrStruct{
- .err_struct = .{
- .struct_field = 1,
- },
- };
-}
test/behavior/bugs/12498.zig
@@ -1,9 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-const S = struct { a: usize };
-test "lazy abi size used in comparison" {
- var rhs: i32 = 100;
- _ = &rhs;
- try expect(@sizeOf(S) < rhs);
-}
test/behavior/bugs/12551.zig
@@ -1,11 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try std.testing.expect(for ([1]u8{0}) |x| {
- if (x == 0) break true;
- } else false);
-}
test/behavior/bugs/12571.zig
@@ -1,23 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
-const Frame = packed struct {
- num: u20,
-};
-
-const Entry = packed struct {
- other: u12,
- frame: Frame,
-};
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const frame = Frame{ .num = 0x7FDE };
- var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
- entry.frame = frame;
- try expect(entry.frame.num == 0x7FDE);
-}
test/behavior/bugs/12644.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-inline fn foo(comptime T: type) !T {
- return error.AnError;
-}
-
-fn main0() !void {
- _ = try foo(u8);
-}
-
-test "issue12644" {
- main0() catch |e| {
- try std.testing.expect(e == error.AnError);
- };
-}
test/behavior/bugs/12723.zig
@@ -1,8 +0,0 @@
-const expect = @import("std").testing.expect;
-
-test "Non-exhaustive enum backed by comptime_int" {
- const E = enum(comptime_int) { a, b, c, _ };
- comptime var e: E = .a;
- e = @as(E, @enumFromInt(378089457309184723749));
- try expect(@intFromEnum(e) == 378089457309184723749);
-}
test/behavior/bugs/1277.zig
@@ -1,21 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const S = struct {
- f: ?*const fn () i32,
-};
-
-const s = S{ .f = &f };
-
-fn f() i32 {
- return 1234;
-}
-
-test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- try std.testing.expect(s.f.?() == 1234);
-}
test/behavior/bugs/12776.zig
@@ -1,47 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const RAM = struct {
- data: [0xFFFF + 1]u8,
- fn new() !RAM {
- return RAM{ .data = [_]u8{0} ** 0x10000 };
- }
- fn get(self: *RAM, addr: u16) u8 {
- return self.data[addr];
- }
-};
-
-const CPU = packed struct {
- interrupts: bool,
- ram: *RAM,
- fn new(ram: *RAM) !CPU {
- return CPU{
- .ram = ram,
- .interrupts = false,
- };
- }
- fn tick(self: *CPU) !void {
- var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);
- _ = &queued_interrupts;
- if (self.interrupts and queued_interrupts != 0) {
- self.interrupts = false;
- }
- }
-};
-
-test {
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64) {
- // Careful enabling this test, fails randomly.
- return error.SkipZigTest;
- }
-
- var ram = try RAM.new();
- var cpu = try CPU.new(&ram);
- try cpu.tick();
- try std.testing.expect(cpu.interrupts == false);
-}
test/behavior/bugs/12786.zig
@@ -1,28 +0,0 @@
-const std = @import("std");
-
-fn NamespacedGlobals(comptime modules: anytype) type {
- return @Type(.{
- .Struct = .{
- .layout = .Auto,
- .is_tuple = false,
- .fields = &.{
- .{
- .name = "globals",
- .type = modules.mach.globals,
- .default_value = null,
- .is_comptime = false,
- .alignment = @alignOf(modules.mach.globals),
- },
- },
- .decls = &[_]std.builtin.Type.Declaration{},
- },
- });
-}
-
-test {
- _ = NamespacedGlobals(.{
- .mach = .{
- .globals = struct {},
- },
- });
-}
test/behavior/bugs/12794.zig
@@ -1,38 +0,0 @@
-const std = @import("std");
-
-fn NamespacedComponents(comptime modules: anytype) type {
- return @Type(.{
- .Struct = .{
- .layout = .Auto,
- .is_tuple = false,
- .fields = &.{.{
- .name = "components",
- .type = @TypeOf(modules.components),
- .default_value = null,
- .is_comptime = false,
- .alignment = @alignOf(@TypeOf(modules.components)),
- }},
- .decls = &[_]std.builtin.Type.Declaration{},
- },
- });
-}
-
-fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) {
- var x: NamespacedComponents(modules) = undefined;
- x.components = modules.components;
- return x;
-}
-
-pub fn World(comptime modules: anytype) type {
- const all_components = namespacedComponents(modules);
- _ = all_components;
- return struct {};
-}
-
-test {
- _ = World(.{
- .components = .{
- .location = struct {},
- },
- });
-}
test/behavior/bugs/12801-1.zig
@@ -1,13 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-comptime capacity: fn () u64 = capacity_,
-fn capacity_() u64 {
- return 64;
-}
-
-test {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- try std.testing.expect((@This(){}).capacity() == 64);
-}
test/behavior/bugs/12801-2.zig
@@ -1,25 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Auto = struct {
- auto: [max_len]u8 = undefined,
- offset: u64 = 0,
-
- comptime capacity: *const fn () u64 = capacity,
-
- const max_len: u64 = 32;
-
- fn capacity() u64 {
- return max_len;
- }
-};
-test {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const a: Auto = .{ .offset = 16, .capacity = Auto.capacity };
- try std.testing.expect(a.capacity() == 32);
- try std.testing.expect((a.capacity)() == 32);
-}
test/behavior/bugs/12885.zig
@@ -1,34 +0,0 @@
-const std = @import("std");
-const builtin = std.builtin;
-const expect = std.testing.expect;
-
-const info = .{
- .args = [_]builtin.Type.Error{
- .{ .name = "bar" },
- },
-};
-const Foo = @Type(.{
- .ErrorSet = &info.args,
-});
-test "ErrorSet comptime_field_ptr" {
- try expect(Foo == error{bar});
-}
-
-const fn_info = .{
- .params = [_]builtin.Type.Fn.Param{
- .{ .is_generic = false, .is_noalias = false, .type = u8 },
- },
-};
-const Bar = @Type(.{
- .Fn = .{
- .calling_convention = .Unspecified,
- .alignment = 0,
- .is_generic = false,
- .is_var_args = false,
- .return_type = void,
- .params = &fn_info.params,
- },
-});
-test "fn comptime_field_ptr" {
- try expect(@typeInfo(Bar) == .Fn);
-}
test/behavior/bugs/12890.zig
@@ -1,18 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-fn a(b: []u3, c: u3) void {
- switch (c) {
- 0...1 => b[c] = c,
- 2...3 => b[c] = c,
- 4...7 => |d| b[d] = c,
- }
-}
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var arr: [8]u3 = undefined;
- a(&arr, 5);
- try expect(arr[5] == 5);
-}
test/behavior/bugs/12891.zig
@@ -1,83 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test "issue12891" {
- const f = 10.0;
- var i: usize = 0;
- _ = &i;
- try std.testing.expect(i < f);
-}
-test "nan" {
- const f = comptime std.math.nan(f64);
- var i: usize = 0;
- _ = &i;
- try std.testing.expect(!(f < i));
-}
-test "inf" {
- const f = comptime std.math.inf(f64);
- var i: usize = 0;
- _ = &i;
- try std.testing.expect(f > i);
-}
-test "-inf < 0" {
- const f = comptime -std.math.inf(f64);
- var i: usize = 0;
- _ = &i;
- try std.testing.expect(f < i);
-}
-test "inf >= 1" {
- const f = comptime std.math.inf(f64);
- var i: usize = 1;
- _ = &i;
- try std.testing.expect(f >= i);
-}
-test "isNan(nan * 1)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const nan_times_one = comptime std.math.nan(f64) * 1;
- try std.testing.expect(std.math.isNan(nan_times_one));
-}
-test "runtime isNan(nan * 1)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const nan_times_one = std.math.nan(f64) * 1;
- try std.testing.expect(std.math.isNan(nan_times_one));
-}
-test "isNan(nan * 0)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const nan_times_zero = comptime std.math.nan(f64) * 0;
- try std.testing.expect(std.math.isNan(nan_times_zero));
- const zero_times_nan = 0 * comptime std.math.nan(f64);
- try std.testing.expect(std.math.isNan(zero_times_nan));
-}
-test "isNan(inf * 0)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const inf_times_zero = comptime std.math.inf(f64) * 0;
- try std.testing.expect(std.math.isNan(inf_times_zero));
- const zero_times_inf = 0 * comptime std.math.inf(f64);
- try std.testing.expect(std.math.isNan(zero_times_inf));
-}
-test "runtime isNan(nan * 0)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const nan_times_zero = std.math.nan(f64) * 0;
- try std.testing.expect(std.math.isNan(nan_times_zero));
- const zero_times_nan = 0 * std.math.nan(f64);
- try std.testing.expect(std.math.isNan(zero_times_nan));
-}
-test "runtime isNan(inf * 0)" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const inf_times_zero = std.math.inf(f64) * 0;
- try std.testing.expect(std.math.isNan(inf_times_zero));
- const zero_times_inf = 0 * std.math.inf(f64);
- try std.testing.expect(std.math.isNan(zero_times_inf));
-}
test/behavior/bugs/12911.zig
@@ -1,9 +0,0 @@
-const builtin = @import("builtin");
-
-const Item = struct { field: u8 };
-const Thing = struct {
- array: [1]Item,
-};
-test {
- _ = Thing{ .array = undefined };
-}
test/behavior/bugs/12928.zig
@@ -1,30 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-const A = extern struct {
- value: *volatile B,
-};
-const B = extern struct {
- a: u32,
- b: i32,
-};
-
-test {
- var a: *A = undefined;
- try expect(@TypeOf(&a.value.a) == *volatile u32);
- try expect(@TypeOf(&a.value.b) == *volatile i32);
-}
-
-const C = extern struct {
- value: *volatile D,
-};
-const D = extern union {
- a: u32,
- b: i32,
-};
-test {
- var c: *C = undefined;
- try expect(@TypeOf(&c.value.a) == *volatile u32);
- try expect(@TypeOf(&c.value.b) == *volatile i32);
-}
test/behavior/bugs/12945.zig
@@ -1,13 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-fn A(
- comptime T: type,
- comptime destroycb: ?*const fn (?*T) callconv(.C) void,
-) !void {
- try expect(destroycb == null);
-}
-
-test {
- try A(u32, null);
-}
test/behavior/bugs/12972.zig
@@ -1,18 +0,0 @@
-const builtin = @import("builtin");
-
-pub fn f(_: [:null]const ?u8) void {}
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const c: u8 = 42;
- f(&[_:null]?u8{c});
- f(&.{c});
-
- var v: u8 = 42;
- _ = &v;
- f(&[_:null]?u8{v});
- f(&.{v});
-}
test/behavior/bugs/12984.zig
@@ -1,20 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-pub fn DeleagateWithContext(comptime Function: type) type {
- const ArgArgs = std.meta.ArgsTuple(Function);
- return struct {
- t: ArgArgs,
- };
-}
-
-pub const OnConfirm = DeleagateWithContext(fn (bool) void);
-pub const CustomDraw = DeleagateWithContext(fn (?OnConfirm) void);
-
-test "simple test" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
-
- var c: CustomDraw = undefined;
- _ = &c;
-}
test/behavior/bugs/13064.zig
@@ -1,17 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-test {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var x: [10][10]u32 = undefined;
-
- x[0][1] = 0;
- const a = x[0];
- x[0][1] = 15;
-
- try expect(a[1] == 0);
-}
test/behavior/bugs/13065.zig
@@ -1,22 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-const U = union(enum) {
- array: [10]u32,
- other: u32,
-};
-
-test {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var x = U{ .array = undefined };
-
- x.array[1] = 0;
- const a = x.array;
- x.array[1] = 15;
-
- try expect(a[1] == 0);
-}
test/behavior/bugs/13068.zig
@@ -1,14 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-pub const allocator = std.heap.page_allocator;
-var list = std.ArrayList(u32).init(allocator);
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- list.items.len = 0;
-}
test/behavior/bugs/13069.zig
@@ -1,17 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-test {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var opt_x: ?[3]f32 = [_]f32{0.0} ** 3;
-
- const x = opt_x.?;
- opt_x.?[0] = 15.0;
-
- try expect(x[0] == 0.0);
-}
test/behavior/bugs/1310.zig
@@ -1,27 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-const builtin = @import("builtin");
-
-pub const VM = ?[*]const struct_InvocationTable_;
-pub const struct_InvocationTable_ = extern struct {
- GetVM: ?*const fn (?[*]VM) callconv(.C) c_int,
-};
-
-pub const struct_VM_ = extern struct {
- functions: ?[*]const struct_InvocationTable_,
-};
-
-//excised output from stdlib.h etc
-
-pub const InvocationTable_ = struct_InvocationTable_;
-pub const VM_ = struct_VM_;
-
-fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
- _ = _vm;
- _ = options;
- return 11;
-}
-
-test {
- try expect(agent_callback(undefined, undefined) == 11);
-}
test/behavior/bugs/13112.zig
@@ -1,7 +0,0 @@
-fn nice(a: u32, b: u32) bool {
- return a == 5 or b == 2 or @panic("oh no");
-}
-
-test {
- _ = nice(2, 2);
-}
test/behavior/bugs/13113.zig
@@ -1,20 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Foo = extern struct {
- a: u8 align(1),
- b: u16 align(1),
-};
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const foo = Foo{
- .a = 1,
- .b = 2,
- };
- try std.testing.expectEqual(1, foo.a);
- try std.testing.expectEqual(2, foo.b);
-}
test/behavior/bugs/13128.zig
@@ -1,29 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-const U = union(enum) {
- x: u128,
- y: [17]u8,
-};
-
-fn foo(val: U) !void {
- try expect(val.x == 1);
-}
-
-test "runtime union init, most-aligned field != largest" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var x: u8 = 1;
- _ = &x;
- try foo(.{ .x = x });
-
- const val: U = @unionInit(U, "x", x);
- try expect(val.x == 1);
-
- const val2: U = .{ .x = x };
- try expect(val2.x == 1);
-}
test/behavior/bugs/13159.zig
@@ -1,18 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
-const Bar = packed struct {
- const Baz = enum {
- fizz,
- buzz,
- };
-};
-
-test {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var foo = Bar.Baz.fizz;
- _ = &foo;
- try expect(foo == .fizz);
-}
test/behavior/bugs/13171.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-fn BuildType(comptime T: type) type {
- return struct {
- val: union {
- b: T,
- },
- };
-}
-
-test {
- const TestStruct = BuildType(u32);
- const c = TestStruct{ .val = .{ .b = 10 } };
- try expect(c.val.b == 10);
-}
test/behavior/bugs/13209.zig
@@ -1,5 +0,0 @@
-const std = @import("std");
-test {
- try std.testing.expect(-1 == @as(i8, -3) >> 2);
- try std.testing.expect(-1 == -3 >> 2000);
-}
test/behavior/bugs/13285.zig
@@ -1,15 +0,0 @@
-const builtin = @import("builtin");
-
-const Crasher = struct {
- lets_crash: u64 = 0,
-};
-
-test {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var a: Crasher = undefined;
- const crasher_ptr = &a;
- var crasher_local = crasher_ptr.*;
- const crasher_local_ptr = &crasher_local;
- crasher_local_ptr.lets_crash = 1;
-}
test/behavior/bugs/13366.zig
@@ -1,28 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
-const ComptimeReason = union(enum) {
- c_import: struct {
- a: u32,
- },
-};
-
-const Block = struct {
- reason: ?*const ComptimeReason,
-};
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var a: u32 = 16;
- _ = &a;
- var reason = .{ .c_import = .{ .a = a } };
- var block = Block{
- .reason = &reason,
- };
- _ = █
- try expect(block.reason.?.c_import.a == 16);
-}
test/behavior/bugs/13435.zig
@@ -1,22 +0,0 @@
-const std = @import("std");
-
-fn CreateUnion(comptime T: type) type {
- return @Type(.{
- .Union = .{
- .layout = .Auto,
- .tag_type = null,
- .fields = &[_]std.builtin.Type.UnionField{
- .{
- .name = "field",
- .type = T,
- .alignment = @alignOf(T),
- },
- },
- .decls = &[_]std.builtin.Type.Declaration{},
- },
- });
-}
-
-test {
- _ = CreateUnion(struct {});
-}
test/behavior/bugs/13664.zig
@@ -1,28 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Fields = packed struct {
- timestamp: u50,
- random_bits: u13,
-};
-const ID = packed union {
- value: u63,
- fields: Fields,
-};
-fn value() i64 {
- return 1341;
-}
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
-
- const timestamp: i64 = value();
- const id = ID{ .fields = Fields{
- .timestamp = @as(u50, @intCast(timestamp)),
- .random_bits = 420,
- } };
- try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);
-}
test/behavior/bugs/13714.zig
@@ -1,5 +0,0 @@
-comptime {
- var image: [1]u8 = undefined;
- _ = ℑ
- _ = @shlExact(@as(u16, image[0]), 8);
-}
test/behavior/bugs/13785.zig
@@ -1,14 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-
-const S = packed struct { a: u0 = 0 };
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var a: u8 = 0;
- _ = &a;
- try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
-}
test/behavior/bugs/1381.zig
@@ -1,27 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const B = union(enum) {
- D: u8,
- E: u16,
-};
-
-const A = union(enum) {
- B: B,
- C: u8,
-};
-
-test "union that needs padding bytes inside an array" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var as = [_]A{
- A{ .B = B{ .D = 1 } },
- A{ .B = B{ .D = 1 } },
- };
- _ = &as;
-
- const a = as[0].B;
- try std.testing.expect(a.D == 1);
-}
test/behavior/bugs/1421.zig
@@ -1,14 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-const builtin = @import("builtin");
-
-const S = struct {
- fn method() std.builtin.Type {
- return @typeInfo(S);
- }
-};
-
-test "functions with return type required to be comptime are generic" {
- const ti = S.method();
- try expect(@as(std.builtin.TypeId, ti) == std.builtin.TypeId.Struct);
-}
test/behavior/bugs/1442.zig
@@ -1,17 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Union = union(enum) {
- Text: []const u8,
- Color: u32,
-};
-
-test "const error union field alignment" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var union_or_err: anyerror!Union = Union{ .Color = 1234 };
- _ = &union_or_err;
- try std.testing.expect((union_or_err catch unreachable).Color == 1234);
-}
test/behavior/bugs/1467.zig
@@ -1,8 +0,0 @@
-pub const E = enum(u32) { A, B, C };
-pub const S = extern struct {
- e: E,
-};
-test "bug 1467" {
- const s: S = undefined;
- _ = s;
-}
test/behavior/bugs/14854.zig
@@ -1,14 +0,0 @@
-const testing = @import("std").testing;
-const builtin = @import("builtin");
-
-test {
- try testing.expect(getGeneric(u8, getU8) == 123);
-}
-
-fn getU8() callconv(.C) u8 {
- return 123;
-}
-
-fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T {
- return supplier();
-}
test/behavior/bugs/1486.zig
@@ -1,14 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-const builtin = @import("builtin");
-
-const ptr = &global;
-var global: usize = 123;
-
-test "constant pointer to global variable causes runtime load" {
- if (builtin.zig_backend == .stage2_aarch64 and builtin.os.tag == .macos) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- global = 1234;
- try expect(&global == ptr);
- try expect(ptr.* == 1234);
-}
test/behavior/bugs/1500.zig
@@ -1,16 +0,0 @@
-const builtin = @import("builtin");
-const A = struct {
- b: B,
-};
-
-const B = *const fn (A) void;
-
-test "allow these dependencies" {
- var a: A = undefined;
- var b: B = undefined;
- _ = .{ &a, &b };
- if (false) {
- a;
- b;
- }
-}
test/behavior/bugs/15778.zig
@@ -1,23 +0,0 @@
-const builtin = @import("builtin");
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- const a = @Vector(0, i32){};
- const b = @Vector(0, i32){};
- _ = a + b;
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- const a = @Vector(0, f32){};
- const b = @Vector(0, f32){};
- _ = a - b;
-}
test/behavior/bugs/1607.zig
@@ -1,20 +0,0 @@
-const std = @import("std");
-const testing = std.testing;
-const builtin = @import("builtin");
-
-const a = [_]u8{ 1, 2, 3 };
-
-fn checkAddress(s: []const u8) !void {
- for (s, 0..) |*i, j| {
- try testing.expect(i == &a[j]);
- }
-}
-
-test "slices pointing at the same address as global array." {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try checkAddress(&a);
- try comptime checkAddress(&a);
-}
test/behavior/bugs/1735.zig
@@ -1,50 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const mystruct = struct {
- pending: ?listofstructs,
-};
-pub fn DoublyLinkedList(comptime T: type) type {
- return struct {
- const Self = @This();
-
- pub const Node = struct {
- prev: ?*Node,
- next: ?*Node,
- data: T,
- };
-
- first: ?*Node,
- last: ?*Node,
- len: usize,
-
- pub fn init() Self {
- return Self{
- .first = null,
- .last = null,
- .len = 0,
- };
- }
- };
-}
-const listofstructs = DoublyLinkedList(mystruct);
-
-const a = struct {
- const Self = @This();
-
- foo: listofstructs,
-
- pub fn init() Self {
- return Self{
- .foo = listofstructs.init(),
- };
- }
-};
-
-test "initialization" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const t = a.init();
- try std.testing.expect(t.foo.len == 0);
-}
test/behavior/bugs/1851.zig
@@ -1,40 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
-test "allocation and looping over 3-byte integer" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
- return error.SkipZigTest; // TODO
- }
-
- if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) {
- return error.SkipZigTest; // TODO
- }
-
- try expect(@sizeOf(u24) == 4);
- try expect(@sizeOf([1]u24) == 4);
- try expect(@alignOf(u24) == 4);
- try expect(@alignOf([1]u24) == 4);
-
- var x = try std.testing.allocator.alloc(u24, 2);
- defer std.testing.allocator.free(x);
- try expect(x.len == 2);
- x[0] = 0xFFFFFF;
- x[1] = 0xFFFFFF;
-
- const bytes = std.mem.sliceAsBytes(x);
- try expect(@TypeOf(bytes) == []align(4) u8);
- try expect(bytes.len == 8);
-
- for (bytes) |*b| {
- b.* = 0x00;
- }
-
- try expect(x[0] == 0x00);
- try expect(x[1] == 0x00);
-}
test/behavior/bugs/1914.zig
@@ -1,32 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const A = struct {
- b_list_pointer: *const []B,
-};
-const B = struct {
- a_pointer: *const A,
-};
-
-const b_list: []B = &[_]B{};
-const a = A{ .b_list_pointer = &b_list };
-
-test "segfault bug" {
- const assert = std.debug.assert;
- const obj = B{ .a_pointer = &a };
- assert(obj.a_pointer == &a); // this makes zig crash
-}
-
-const A2 = struct {
- pointer: *B,
-};
-
-pub const B2 = struct {
- pointer_array: []*A2,
-};
-
-var b_value = B2{ .pointer_array = &[_]*A2{} };
-
-test "basic stuff" {
- std.debug.assert(&b_value == &b_value);
-}
test/behavior/bugs/2006.zig
@@ -1,15 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-const builtin = @import("builtin");
-
-const S = struct {
- p: *S,
-};
-test "bug 2006" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var a: S = undefined;
- a = S{ .p = undefined };
- try expect(@sizeOf(S) != 0);
- try expect(@sizeOf(*void) == @sizeOf(*i32));
-}
test/behavior/bugs/2114.zig
@@ -1,27 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-const math = std.math;
-
-fn ctz(x: anytype) usize {
- return @ctz(x);
-}
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- try testCtz();
- try comptime testCtz();
-}
-
-fn testCtz() !void {
- try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
- try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
- try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
- try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
-}
test/behavior/bugs/2346.zig
@@ -1,10 +0,0 @@
-const builtin = @import("builtin");
-
-test "fixed" {
- const a: *void = undefined;
- const b: *[1]void = a;
- _ = b;
- const c: *[0]u8 = undefined;
- const d: []u8 = c;
- _ = d;
-}
test/behavior/bugs/2557.zig
@@ -1,6 +0,0 @@
-test {
- var a = if (true) {
- return;
- } else true;
- _ = &a;
-}
test/behavior/bugs/2578.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-
-const Foo = struct {
- y: u8,
-};
-
-var foo: Foo = undefined;
-const t = &foo;
-
-fn bar(pointer: ?*anyopaque) void {
- _ = pointer;
-}
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- bar(t);
-}
test/behavior/bugs/2622.zig
@@ -1,14 +0,0 @@
-const builtin = @import("builtin");
-
-var buf: []u8 = undefined;
-
-test "reslice of undefined global var slice" {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var mem: [100]u8 = [_]u8{0} ** 100;
- buf = &mem;
- const x = buf[0..1];
- try @import("std").testing.expect(x.len == 1 and x[0] == 0);
-}
test/behavior/bugs/2692.zig
@@ -1,13 +0,0 @@
-const builtin = @import("builtin");
-
-fn foo(a: []u8) void {
- _ = a;
-}
-
-test "address of 0 length array" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var pt: [0]u8 = undefined;
- foo(&pt);
-}
test/behavior/bugs/2727.zig
@@ -1,16 +0,0 @@
-const builtin = @import("builtin");
-
-fn t() bool {
- return true;
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- comptime var i: usize = 0;
- inline while (i < 2) : (i += 1) {
- if (t()) {} else return;
- }
-}
test/behavior/bugs/2889.zig
@@ -1,36 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const source = "A-";
-
-fn parseNote() ?i32 {
- const letter = source[0];
- const modifier = source[1];
-
- const semitone = blk: {
- if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
- if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
- if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
- if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
- if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
- if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
- if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
- if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
- if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
- if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
- if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
- if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
- return null;
- };
-
- return semitone;
-}
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const result = parseNote();
- try std.testing.expect(result.? == 9);
-}
test/behavior/bugs/3007.zig
@@ -1,28 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const Foo = struct {
- free: bool,
-
- pub const FooError = error{NotFree};
-};
-
-var foo = Foo{ .free = true };
-var default_foo: ?*Foo = null;
-
-fn get_foo() Foo.FooError!*Foo {
- if (foo.free) {
- foo.free = false;
- return &foo;
- }
- return error.NotFree;
-}
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- default_foo = get_foo() catch null; // This Line
- try std.testing.expect(!default_foo.?.free);
-}
test/behavior/bugs/3046.zig
@@ -1,24 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-const SomeStruct = struct {
- field: i32,
-};
-
-fn couldFail() anyerror!i32 {
- return 1;
-}
-
-var some_struct: SomeStruct = undefined;
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- some_struct = SomeStruct{
- .field = couldFail() catch @as(i32, 0),
- };
- try expect(some_struct.field == 1);
-}
test/behavior/bugs/3112.zig
@@ -1,23 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
-const State = struct {
- const Self = @This();
- enter: *const fn (previous: ?Self) void,
-};
-
-fn prev(p: ?State) void {
- expect(p == null) catch @panic("test failure");
-}
-
-test "zig test crash" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var global: State = undefined;
- global.enter = prev;
- global.enter(null);
-}
test/behavior/bugs/3367.zig
@@ -1,15 +0,0 @@
-const builtin = @import("builtin");
-const Foo = struct {
- usingnamespace Mixin;
-};
-
-const Mixin = struct {
- pub fn two(self: Foo) void {
- _ = self;
- }
-};
-
-test "container member access usingnamespace decls" {
- var foo = Foo{};
- foo.two();
-}
test/behavior/bugs/3384.zig
@@ -1,11 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-test "resolve array slice using builtin" {
- try expect(@hasDecl(@This(), "std") == true);
- try expect(@hasDecl(@This(), "std"[0..0]) == false);
- try expect(@hasDecl(@This(), "std"[0..1]) == false);
- try expect(@hasDecl(@This(), "std"[0..2]) == false);
- try expect(@hasDecl(@This(), "std"[0..3]) == true);
- try expect(@hasDecl(@This(), "std"[0..]) == true);
-}
test/behavior/bugs/3468.zig
@@ -1,7 +0,0 @@
-// zig fmt: off
-test "pointer deref next to assignment" {
- var a:i32=2;
- var b=&a;
- b.*=3;
- _=&b;
-}
test/behavior/bugs/3586.zig
@@ -1,16 +0,0 @@
-const builtin = @import("builtin");
-
-const NoteParams = struct {};
-
-const Container = struct {
- params: ?NoteParams,
-};
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var ctr = Container{
- .params = NoteParams{},
- };
- _ = &ctr;
-}
test/behavior/bugs/3742.zig
@@ -1,45 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-pub const GET = struct {
- key: []const u8,
-
- pub fn init(key: []const u8) GET {
- return .{ .key = key };
- }
-
- pub const Redis = struct {
- pub const Command = struct {
- pub fn serialize(self: GET, comptime rootSerializer: type) void {
- return rootSerializer.serializeCommand(.{ "GET", self.key });
- }
- };
- };
-};
-
-pub fn isCommand(comptime T: type) bool {
- const tid = @typeInfo(T);
- return (tid == .Struct or tid == .Enum or tid == .Union) and
- @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
-}
-
-pub const ArgSerializer = struct {
- pub fn serializeCommand(command: anytype) void {
- const CmdT = @TypeOf(command);
-
- if (comptime isCommand(CmdT)) {
- // COMMENTING THE NEXT LINE REMOVES THE ERROR
- return CmdT.Redis.Command.serialize(command, ArgSerializer);
- }
- }
-};
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_llvm and
- builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest;
-
- ArgSerializer.serializeCommand(GET.init("banana"));
-}
test/behavior/bugs/394.zig
@@ -1,19 +0,0 @@
-const E = union(enum) {
- A: [9]u8,
- B: u64,
-};
-const S = struct {
- x: u8,
- y: E,
-};
-
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-test "fixed" {
- const x = S{
- .x = 3,
- .y = E{ .B = 1 },
- };
- try expect(x.x == 3);
-}
test/behavior/bugs/421.zig
@@ -1,21 +0,0 @@
-const builtin = @import("builtin");
-const expect = @import("std").testing.expect;
-
-test "bitCast to array" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- try comptime testBitCastArray();
- try testBitCastArray();
-}
-
-fn testBitCastArray() !void {
- try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
-}
-
-fn extractOne64(a: u128) u64 {
- const x = @as([2]u64, @bitCast(a));
- return x[1];
-}
test/behavior/bugs/4328.zig
@@ -1,82 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-const FILE = extern struct {
- dummy_field: u8,
-};
-
-extern fn c_printf([*c]const u8, ...) c_int;
-extern fn c_fputs([*c]const u8, noalias [*c]FILE) c_int;
-extern fn c_ftell([*c]FILE) c_long;
-extern fn c_fopen([*c]const u8, [*c]const u8) [*c]FILE;
-
-const S = extern struct {
- state: c_short,
-
- extern fn s_do_thing([*c]const S, b: c_int) c_short;
-};
-
-test "Extern function calls in @TypeOf" {
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const Test = struct {
- fn test_fn_1(a: anytype, b: anytype) @TypeOf(c_printf("%d %s\n", a, b)) {
- return 0;
- }
-
- fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) {
- return 1;
- }
-
- fn doTheTest() !void {
- try expect(@TypeOf(test_fn_1(0, 42)) == c_int);
- try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short);
- }
- };
-
- try Test.doTheTest();
- try comptime Test.doTheTest();
-}
-
-test "Peer resolution of extern function calls in @TypeOf" {
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const Test = struct {
- fn test_fn() @TypeOf(c_ftell(null), c_fputs(null, null)) {
- return 0;
- }
-
- fn doTheTest() !void {
- try expect(@TypeOf(test_fn()) == c_long);
- }
- };
-
- try Test.doTheTest();
- try comptime Test.doTheTest();
-}
-
-test "Extern function calls, dereferences and field access in @TypeOf" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- const Test = struct {
- fn test_fn_1(a: c_long) @TypeOf(c_fopen("test", "r").*) {
- _ = a;
- return .{ .dummy_field = 0 };
- }
-
- fn test_fn_2(a: anytype) @TypeOf(c_fopen("test", "r").*.dummy_field) {
- _ = a;
- return 255;
- }
-
- fn doTheTest() !void {
- try expect(@TypeOf(test_fn_1(0)) == FILE);
- try expect(@TypeOf(test_fn_2(0)) == u8);
- }
- };
-
- try Test.doTheTest();
- try comptime Test.doTheTest();
-}
test/behavior/bugs/4560.zig
@@ -1,40 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var s: S = .{
- .a = 1,
- .b = .{
- .size = 123,
- .max_distance_from_start_index = 456,
- },
- };
- _ = &s;
- try std.testing.expect(s.a == 1);
- try std.testing.expect(s.b.size == 123);
- try std.testing.expect(s.b.max_distance_from_start_index == 456);
-}
-
-const S = struct {
- a: u32,
- b: Map,
-
- const Map = StringHashMap(*S);
-};
-
-pub fn StringHashMap(comptime V: type) type {
- return HashMap([]const u8, V);
-}
-
-pub fn HashMap(comptime K: type, comptime V: type) type {
- if (false) {
- K;
- V;
- }
- return struct {
- size: usize,
- max_distance_from_start_index: usize,
- };
-}
test/behavior/bugs/4769_a.zig
@@ -1,1 +0,0 @@
-//
test/behavior/bugs/4769_b.zig
@@ -1,1 +0,0 @@
-//!
test/behavior/bugs/4954.zig
@@ -1,14 +0,0 @@
-const builtin = @import("builtin");
-
-fn f(buf: []u8) void {
- _ = &buf[@sizeOf(u32)];
-}
-
-test "crash" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var buf: [4096]u8 = undefined;
- f(&buf);
-}
test/behavior/bugs/5398.zig
@@ -1,36 +0,0 @@
-const std = @import("std");
-const testing = std.testing;
-const builtin = @import("builtin");
-
-pub const Mesh = struct {
- id: u32,
-};
-pub const Material = struct {
- transparent: bool = true,
- emits_shadows: bool = true,
- render_color: bool = true,
-};
-pub const Renderable = struct {
- material: Material,
- // The compiler inserts some padding here to ensure Mesh is correctly aligned.
- mesh: Mesh,
-};
-
-var renderable: Renderable = undefined;
-
-test "assignment of field with padding" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- renderable = Renderable{
- .mesh = Mesh{ .id = 0 },
- .material = Material{
- .transparent = false,
- .emits_shadows = false,
- },
- };
- try testing.expect(false == renderable.material.transparent);
- try testing.expect(false == renderable.material.emits_shadows);
- try testing.expect(true == renderable.material.render_color);
-}
test/behavior/bugs/5413.zig
@@ -1,6 +0,0 @@
-const expect = @import("std").testing.expect;
-
-test "Peer type resolution with string literals and unknown length u8 pointers" {
- try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
- try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
-}
test/behavior/bugs/5474.zig
@@ -1,63 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-// baseline (control) struct with array of scalar
-const Box0 = struct {
- items: [4]Item,
-
- const Item = struct {
- num: u32,
- };
-};
-
-// struct with array of empty struct
-const Box1 = struct {
- items: [4]Item,
-
- const Item = struct {};
-};
-
-// struct with array of zero-size struct
-const Box2 = struct {
- items: [4]Item,
-
- const Item = struct {
- nothing: void,
- };
-};
-
-fn mutable() !void {
- var box0: Box0 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
-
- var box1: Box1 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
-
- var box2: Box2 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
-}
-
-fn constant() !void {
- const box0: Box0 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
-
- const box1: Box1 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
-
- const box2: Box2 = .{ .items = undefined };
- try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
-}
-
-test "pointer-to-array constness for zero-size elements, var" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try mutable();
- try comptime mutable();
-}
-
-test "pointer-to-array constness for zero-size elements, const" {
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try constant();
- try comptime constant();
-}
test/behavior/bugs/5487.zig
@@ -1,17 +0,0 @@
-const io = @import("std").io;
-const builtin = @import("builtin");
-
-pub fn write(_: void, bytes: []const u8) !usize {
- _ = bytes;
- return 0;
-}
-pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) {
- return io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} };
-}
-
-test "crash" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- _ = io.multiWriter(.{writer()});
-}
test/behavior/bugs/6047.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-
-fn getError() !void {
- return error.Test;
-}
-
-fn getError2() !void {
- var a: u8 = 'c';
- _ = &a;
- try if (a == 'a') getError() else if (a == 'b') getError() else getError();
-}
-
-test "`try`ing an if/else expression" {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- try @import("std").testing.expectError(error.Test, getError2());
-}
test/behavior/bugs/624.zig
@@ -1,30 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-const TestContext = struct {
- server_context: *ListenerContext,
-};
-
-const ListenerContext = struct {
- context_alloc: *ContextAllocator,
-};
-
-const ContextAllocator = MemoryPool(TestContext);
-
-fn MemoryPool(comptime T: type) type {
- _ = T;
- return struct {
- n: usize,
- };
-}
-
-test "foo" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- var allocator = ContextAllocator{ .n = 10 };
- _ = &allocator;
- try expect(allocator.n == 10);
-}
test/behavior/bugs/6305.zig
@@ -1,10 +0,0 @@
-const ListNode = struct {
- next: ?*const @This() = null,
-};
-
-test "copy array of self-referential struct" {
- comptime var nodes = [_]ListNode{ .{}, .{} };
- nodes[0].next = &nodes[1];
- const copy = nodes;
- _ = copy;
-}
test/behavior/bugs/6456.zig
@@ -1,46 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const testing = std.testing;
-const StructField = std.builtin.Type.StructField;
-const Declaration = std.builtin.Type.Declaration;
-
-const text =
- \\f1
- \\f2
- \\f3
-;
-
-test "issue 6456" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- comptime {
- var fields: []const StructField = &[0]StructField{};
-
- var it = std.mem.tokenizeScalar(u8, text, '\n');
- while (it.next()) |name| {
- fields = fields ++ &[_]StructField{StructField{
- .alignment = 0,
- .name = name,
- .type = usize,
- .default_value = null,
- .is_comptime = false,
- }};
- }
-
- const T = @Type(.{
- .Struct = .{
- .layout = .Auto,
- .is_tuple = false,
- .fields = fields,
- .decls = &[_]Declaration{},
- },
- });
-
- const gen_fields = @typeInfo(T).Struct.fields;
- try testing.expectEqual(3, gen_fields.len);
- try testing.expectEqualStrings("f1", gen_fields[0].name);
- try testing.expectEqualStrings("f2", gen_fields[1].name);
- try testing.expectEqualStrings("f3", gen_fields[2].name);
- }
-}
test/behavior/bugs/655.zig
@@ -1,12 +0,0 @@
-const std = @import("std");
-const other_file = @import("655_other_file.zig");
-
-test "function with *const parameter with type dereferenced by namespace" {
- const x: other_file.Integer = 1234;
- try comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
- try foo(&x);
-}
-
-fn foo(x: *const other_file.Integer) !void {
- try std.testing.expect(x.* == 1234);
-}
test/behavior/bugs/655_other_file.zig
@@ -1,1 +0,0 @@
-pub const Integer = u32;
test/behavior/bugs/656.zig
@@ -1,37 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-const PrefixOp = union(enum) {
- Return,
- AddrOf: Value,
-};
-
-const Value = struct {
- align_expr: ?u32,
-};
-
-test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- try foo(false, true);
-}
-
-fn foo(a: bool, b: bool) !void {
- var prefix_op = PrefixOp{
- .AddrOf = Value{ .align_expr = 1234 },
- };
- _ = &prefix_op;
- if (a) {} else {
- switch (prefix_op) {
- PrefixOp.AddrOf => |addr_of_info| {
- if (b) {}
- if (addr_of_info.align_expr) |align_expr| {
- try expect(align_expr == 1234);
- }
- },
- PrefixOp.Return => {},
- }
- }
-}
test/behavior/bugs/6781.zig
@@ -1,84 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const assert = std.debug.assert;
-
-const segfault = true;
-
-pub const JournalHeader = packed struct {
- hash_chain_root: u128 = undefined,
- prev_hash_chain_root: u128,
- checksum: u128 = undefined,
- magic: u64,
- command: u32,
- size: u32,
-
- pub fn calculate_checksum(self: *const JournalHeader, entry: []const u8) u128 {
- assert(entry.len >= @sizeOf(JournalHeader));
- assert(entry.len == self.size);
-
- const checksum_offset = @offsetOf(JournalHeader, "checksum");
- const checksum_size = @sizeOf(@TypeOf(self.checksum));
- assert(checksum_offset == 0 + 16 + 16);
- assert(checksum_size == 16);
-
- var target: [32]u8 = undefined;
- std.crypto.hash.Blake3.hash(entry[checksum_offset + checksum_size ..], target[0..], .{});
- return @as(u128, @bitCast(target[0..checksum_size].*));
- }
-
- pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 {
- const hash_chain_root_size = @sizeOf(@TypeOf(self.hash_chain_root));
- assert(hash_chain_root_size == 16);
-
- const prev_hash_chain_root_offset = @offsetOf(JournalHeader, "prev_hash_chain_root");
- const prev_hash_chain_root_size = @sizeOf(@TypeOf(self.prev_hash_chain_root));
- assert(prev_hash_chain_root_offset == 0 + 16);
- assert(prev_hash_chain_root_size == 16);
-
- const checksum_offset = @offsetOf(JournalHeader, "checksum");
- const checksum_size = @sizeOf(@TypeOf(self.checksum));
- assert(checksum_offset == 0 + 16 + 16);
- assert(checksum_size == 16);
-
- assert(prev_hash_chain_root_offset + prev_hash_chain_root_size == checksum_offset);
-
- const header = @as([@sizeOf(JournalHeader)]u8, @bitCast(self.*));
- const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size];
- assert(source.len == prev_hash_chain_root_size + checksum_size);
- var target: [32]u8 = undefined;
- std.crypto.hash.Blake3.hash(source, target[0..], .{});
- if (segfault) {
- return @as(u128, @bitCast(target[0..hash_chain_root_size].*));
- } else {
- var array = target[0..hash_chain_root_size].*;
- _ = &array;
- return @bitCast(array);
- }
- }
-
- pub fn set_checksum_and_hash_chain_root(self: *JournalHeader, entry: []const u8) void {
- self.checksum = self.calculate_checksum(entry);
- self.hash_chain_root = self.calculate_hash_chain_root();
- }
-};
-
-test "fixed" {
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
-
- var buffer align(@alignOf(JournalHeader)) = [_]u8{0} ** 65536;
- var entry = std.mem.bytesAsValue(JournalHeader, buffer[0..@sizeOf(JournalHeader)]);
- entry.* = .{
- .prev_hash_chain_root = 0,
- .magic = 0,
- .command = 0,
- .size = 64 + 128,
- };
- entry.set_checksum_and_hash_chain_root(buffer[0..entry.size]);
- try std.io.null_writer.print("{}\n", .{entry});
-}
test/behavior/bugs/679.zig
@@ -1,19 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-pub fn List(comptime T: type) type {
- _ = T;
- return u32;
-}
-
-const ElementList = List(Element);
-const Element = struct {
- link: ElementList,
-};
-
-test "false dependency loop in struct definition" {
- const listType = ElementList;
- var x: listType = 42;
- _ = &x;
- try expect(x == 42);
-}
test/behavior/bugs/6850.zig
@@ -1,12 +0,0 @@
-const std = @import("std");
-
-test "lazy sizeof comparison with zero" {
- const Empty = struct {};
- const T = *Empty;
-
- try std.testing.expect(hasNoBits(T));
-}
-
-fn hasNoBits(comptime T: type) bool {
- return @sizeOf(T) == @sizeOf(*i32);
-}
test/behavior/bugs/6905.zig
@@ -1,23 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-test "sentinel-terminated 0-length slices" {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
-
- var index: u8 = 2;
- _ = &index;
- const slice = u32s[index..index :2];
- const array_ptr = u32s[2..2 :2];
- const comptime_known_array_value = u32s[2..2 :2].*;
- var runtime_array_value = u32s[2..2 :2].*;
- _ = &runtime_array_value;
-
- try expect(slice[0] == 2);
- try expect(array_ptr[0] == 2);
- try expect(comptime_known_array_value[0] == 2);
- try expect(runtime_array_value[0] == 2);
-}
test/behavior/bugs/6947.zig
@@ -1,14 +0,0 @@
-const builtin = @import("builtin");
-
-fn destroy(ptr: *void) void {
- _ = ptr;
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var slice: []void = undefined;
- destroy(&slice[0]);
-}
test/behavior/bugs/7003.zig
@@ -1,9 +0,0 @@
-test "@Type should resolve its children types" {
- const sparse = enum(u2) { a, b, c };
- const dense = enum(u2) { a, b, c, d };
-
- comptime var sparse_info = @typeInfo(anyerror!sparse);
- sparse_info.ErrorUnion.payload = dense;
- const B = @Type(sparse_info);
- _ = B;
-}
test/behavior/bugs/704.zig
@@ -1,11 +0,0 @@
-const builtin = @import("builtin");
-
-const xxx = struct {
- pub fn bar(self: *xxx) void {
- _ = self;
- }
-};
-test "bug 704" {
- var x: xxx = undefined;
- x.bar();
-}
test/behavior/bugs/7047.zig
@@ -1,23 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const U = union(enum) {
- T: type,
- N: void,
-};
-
-fn S(comptime query: U) type {
- return struct {
- fn tag() type {
- return query.T;
- }
- };
-}
-
-test "compiler doesn't consider equal unions with different 'type' payload" {
- const s1 = S(U{ .T = u32 }).tag();
- try std.testing.expectEqual(u32, s1);
-
- const s2 = S(U{ .T = u64 }).tag();
- try std.testing.expectEqual(u64, s2);
-}
test/behavior/bugs/718.zig
@@ -1,23 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const mem = std.mem;
-const expect = std.testing.expect;
-const Keys = struct {
- up: bool,
- down: bool,
- left: bool,
- right: bool,
-};
-var keys: Keys = undefined;
-test "zero keys with @memset" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- @memset(@as([*]u8, @ptrCast(&keys))[0..@sizeOf(@TypeOf(keys))], 0);
- try expect(!keys.up);
- try expect(!keys.down);
- try expect(!keys.left);
- try expect(!keys.right);
-}
test/behavior/bugs/7187.zig
@@ -1,15 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const expect = std.testing.expect;
-
-test "miscompilation with bool return type" {
- var x: usize = 1;
- var y: bool = getFalse();
- _ = .{ &x, &y };
-
- try expect(x == 1);
-}
-
-fn getFalse() bool {
- return false;
-}
test/behavior/bugs/726.zig
@@ -1,26 +0,0 @@
-const expect = @import("std").testing.expect;
-const builtin = @import("builtin");
-
-test "@ptrCast from const to nullable" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const c: u8 = 4;
- var x: ?*const u8 = @ptrCast(&c);
- _ = &x;
- try expect(x.?.* == 4);
-}
-
-test "@ptrCast from var in empty struct to nullable" {
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
- const container = struct {
- var c: u8 = 4;
- };
- var x: ?*const u8 = @ptrCast(&container.c);
- _ = &x;
- try expect(x.?.* == 4);
-}
test/behavior/bugs/7325.zig
@@ -1,113 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const testing = std.testing;
-
-const string = "hello world";
-
-const TempRef = struct {
- index: usize,
- is_weak: bool,
-};
-
-const BuiltinEnum = struct {
- name: []const u8,
-};
-
-const ParamType = union(enum) {
- boolean,
- buffer,
- one_of: BuiltinEnum,
-};
-
-const CallArg = struct {
- value: Expression,
-};
-
-const Expression = union(enum) {
- literal_boolean: bool,
- literal_enum_value: EnumLiteral,
-};
-
-const EnumLiteral = struct {
- label: []const u8,
-};
-
-const ExpressionResult = union(enum) {
- temp_buffer: TempRef,
- literal_boolean: bool,
- literal_enum_value: []const u8,
-};
-
-fn commitCalleeParam(result: ExpressionResult, callee_param_type: ParamType) ExpressionResult {
- switch (callee_param_type) {
- .boolean => {
- return result;
- },
- .buffer => {
- return ExpressionResult{
- .temp_buffer = .{ .index = 0, .is_weak = false },
- };
- },
- .one_of => {
- return result;
- },
- }
-}
-
-fn genExpression(expr: Expression) !ExpressionResult {
- switch (expr) {
- .literal_boolean => |value| {
- return ExpressionResult{
- .literal_boolean = value,
- };
- },
- .literal_enum_value => |v| {
- try testing.expectEqualStrings(string, v.label);
- const result: ExpressionResult = .{
- .literal_enum_value = v.label,
- };
- switch (result) {
- .literal_enum_value => |w| {
- try testing.expectEqualStrings(string, w);
- },
- else => {},
- }
- return result;
- },
- }
-}
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- var param: ParamType = .{
- .one_of = .{ .name = "name" },
- };
- _ = ¶m;
- var arg: CallArg = .{
- .value = .{
- .literal_enum_value = .{
- .label = string,
- },
- },
- };
- _ = &arg;
-
- const result = try genExpression(arg.value);
- switch (result) {
- .literal_enum_value => |w| {
- try testing.expectEqualStrings(string, w);
- },
- else => {},
- }
-
- const derp = commitCalleeParam(result, param);
- switch (derp) {
- .literal_enum_value => |w| {
- try testing.expectEqualStrings(string, w);
- },
- else => {},
- }
-}
test/behavior/bugs/8277.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-test "@sizeOf reified union zero-size payload fields" {
- comptime {
- try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union {}))));
- try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void }))));
- if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) {
- try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void }))));
- try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void }))));
- } else {
- try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void }))));
- try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void }))));
- }
- }
-}
test/behavior/bugs/828.zig
@@ -1,43 +0,0 @@
-const builtin = @import("builtin");
-
-const CountBy = struct {
- a: usize,
-
- const One = CountBy{ .a = 1 };
-
- pub fn counter(self: *const CountBy) Counter {
- _ = self;
- return Counter{ .i = 0 };
- }
-};
-
-const Counter = struct {
- i: usize,
-
- pub fn count(self: *Counter) bool {
- self.i += 1;
- return self.i <= 10;
- }
-};
-
-fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
- _ = unused;
- comptime {
- var cnt = cb.counter();
- if (cnt.i != 0) @compileError("Counter instance reused!");
- while (cnt.count()) {}
- }
-}
-
-test "comptime struct return should not return the same instance" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
-
- //the first parameter must be passed by reference to trigger the bug
- //a second parameter is required to trigger the bug
- const ValA = constCount(&CountBy.One, 12);
- const ValB = constCount(&CountBy.One, 15);
- if (false) {
- ValA;
- ValB;
- }
-}
test/behavior/bugs/8646.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-
-const array = [_][]const []const u8{
- &.{"hello"},
- &.{ "world", "hello" },
-};
-
-test {
- if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
-
- try std.testing.expect(array[0].len == 1);
- try std.testing.expectEqualStrings("hello", array[0][0]);
-}
test/behavior/bugs/920.zig
@@ -1,80 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const Random = std.rand.Random;
-
-const ZigTable = struct {
- r: f64,
- x: [257]f64,
- f: [257]f64,
-
- pdf: *const fn (f64) f64,
- is_symmetric: bool,
- zero_case: *const fn (*Random, f64) f64,
-};
-
-fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (*Random, f64) f64) ZigTable {
- var tables: ZigTable = undefined;
-
- tables.is_symmetric = is_symmetric;
- tables.r = r;
- tables.pdf = f;
- tables.zero_case = zero_case;
-
- tables.x[0] = v / f(r);
- tables.x[1] = r;
-
- for (tables.x[2..256], 0..) |*entry, i| {
- const last = tables.x[2 + i - 1];
- entry.* = f_inv(v / last + f(last));
- }
- tables.x[256] = 0;
-
- for (tables.f[0..], 0..) |*entry, i| {
- entry.* = f(tables.x[i]);
- }
-
- return tables;
-}
-
-const norm_r = 3.6541528853610088;
-const norm_v = 0.00492867323399;
-
-fn norm_f(x: f64) f64 {
- return @exp(-x * x / 2.0);
-}
-fn norm_f_inv(y: f64) f64 {
- return @sqrt(-2.0 * @log(y));
-}
-fn norm_zero_case(random: *Random, u: f64) f64 {
- _ = random;
- _ = u;
- return 0.0;
-}
-
-const NormalDist = blk: {
- @setEvalBranchQuota(30000);
- break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case);
-};
-
-test "bug 920 fixed" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
-
- const NormalDist1 = blk: {
- break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case);
- };
-
- for (NormalDist1.f, 0..) |_, i| {
- // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small
- // differences in math functions of different libcs. For example, if the compiler
- // links against glibc, but the target is musl libc, then these values might be
- // slightly different.
- // Arguably, this is a bug in the compiler because comptime should emulate the target,
- // including rounding errors in libc math functions. However that behavior is not
- // what this particular test is intended to cover.
- try std.testing.expectApproxEqAbs(NormalDist1.f[i], NormalDist.f[i], @sqrt(std.math.floatEps(f64)));
- }
-}
test/behavior/bugs/9584.zig
@@ -1,69 +0,0 @@
-const builtin = @import("builtin");
-const std = @import("std");
-
-const A = packed struct {
- a: bool,
- b: bool,
- c: bool,
- d: bool,
-
- e: bool,
- f: bool,
- g: bool,
- h: bool,
-};
-
-const X = union {
- x: A,
- y: u64,
-};
-
-pub fn a(
- x0: i32,
- x1: i32,
- x2: i32,
- x3: i32,
- x4: i32,
- flag_a: bool,
- flag_b: bool,
-) !void {
- _ = x0;
- _ = x1;
- _ = x2;
- _ = x3;
- _ = x4;
- _ = flag_a;
- // With this bug present, `flag_b` would actually contain the value 17.
- // Note: this bug only presents itself on debug mode.
- const flag_b_byte: u8 = @intFromBool(flag_b);
- try std.testing.expect(flag_b_byte == 1);
-}
-
-pub fn b(x: *X) !void {
- try a(0, 1, 2, 3, 4, x.x.a, x.x.b);
-}
-
-test {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
-
- var flags = A{
- .a = false,
- .b = true,
- .c = false,
- .d = false,
-
- .e = false,
- .f = true,
- .g = false,
- .h = false,
- };
- _ = &flags;
- var x = X{
- .x = flags,
- };
- try b(&x);
- comptime if (@sizeOf(A) != 1) unreachable;
-}
test/behavior/bugs/529_other_file.zig โ test/behavior/conflicting_externs/a.zig
@@ -1,5 +1,4 @@
pub const A = extern struct {
field: c_int,
};
-
pub extern fn issue529(?*A) void;
test/behavior/bugs/529_other_file_2.zig โ test/behavior/conflicting_externs/b.zig
File renamed without changes
test/behavior/array.zig
@@ -827,3 +827,121 @@ test "tuple initialized through reference to anonymous array init provides resul
try expect(foo[0] == 12345);
try expect(@intFromPtr(foo[1]) == 0x1000);
}
+
+test "copied array element doesn't alias source" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ var x: [10][10]u32 = undefined;
+
+ x[0][1] = 0;
+ const a = x[0];
+ x[0][1] = 15;
+
+ try expect(a[1] == 0);
+}
+
+test "array initialized with string literal" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ a: u32,
+ c: [5]u8,
+ };
+ const U = union {
+ s: S,
+ };
+ const s_1 = S{
+ .a = undefined,
+ .c = "12345".*, // this caused problems
+ };
+
+ var u_2 = U{ .s = s_1 };
+ _ = &u_2;
+ try std.testing.expectEqualStrings("12345", &u_2.s.c);
+}
+
+test "array initialized with array with sentinel" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ a: u32,
+ c: [5]u8,
+ };
+ const U = union {
+ s: S,
+ };
+ const c = [5:0]u8{ 1, 2, 3, 4, 5 };
+ const s_1 = S{
+ .a = undefined,
+ .c = c, // this caused problems
+ };
+ var u_2 = U{ .s = s_1 };
+ _ = &u_2;
+ try std.testing.expectEqualSlices(u8, &.{ 1, 2, 3, 4, 5 }, &u_2.s.c);
+}
+
+test "store array of array of structs at comptime" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn storeArrayOfArrayOfStructs() u8 {
+ const S = struct {
+ x: u8,
+ };
+
+ var cases = [_][1]S{
+ [_]S{
+ S{ .x = 15 },
+ },
+ };
+ _ = &cases;
+ return cases[0][0].x;
+ }
+ };
+
+ try expect(S.storeArrayOfArrayOfStructs() == 15);
+ try comptime expect(S.storeArrayOfArrayOfStructs() == 15);
+}
+
+test "accessing multidimensional global array at comptime" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ const array = [_][]const []const u8{
+ &.{"hello"},
+ &.{ "world", "hello" },
+ };
+ };
+
+ try std.testing.expect(S.array[0].len == 1);
+ try std.testing.expectEqualStrings("hello", S.array[0][0]);
+}
+
+test "union that needs padding bytes inside an array" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const B = union(enum) {
+ D: u8,
+ E: u16,
+ };
+ const A = union(enum) {
+ B: B,
+ C: u8,
+ };
+ var as = [_]A{
+ A{ .B = B{ .D = 1 } },
+ A{ .B = B{ .D = 1 } },
+ };
+ _ = &as;
+
+ const a = as[0].B;
+ try std.testing.expect(a.D == 1);
+}
test/behavior/basic.zig
@@ -1219,3 +1219,184 @@ test "integer compare" {
try comptime S.doTheTestSigned(T);
}
}
+
+test "reference to inferred local variable works as expected" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const Crasher = struct {
+ lets_crash: u64 = 0,
+ };
+
+ var a: Crasher = undefined;
+ const crasher_ptr = &a;
+ var crasher_local = crasher_ptr.*;
+ const crasher_local_ptr = &crasher_local;
+ crasher_local_ptr.lets_crash = 1;
+
+ try expect(crasher_local.lets_crash != a.lets_crash);
+}
+
+test "@Type returned from block" {
+ const T = comptime b: {
+ break :b @Type(.{ .Int = .{
+ .signedness = .unsigned,
+ .bits = 8,
+ } });
+ };
+ try std.testing.expect(T == u8);
+}
+
+test "comptime variable initialized with addresses of literals" {
+ comptime var st = .{
+ .foo = &1,
+ .bar = &2,
+ };
+ _ = &st;
+
+ inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
+ _ = field;
+ }
+}
+
+test "pointer to tuple field can be dereferenced at comptime" {
+ comptime {
+ const tuple_with_ptrs = .{ &0, &0 };
+ const field_ptr = (&tuple_with_ptrs.@"0");
+ _ = field_ptr.*;
+ }
+}
+
+test "proper value is returned from labeled block" {
+ const S = struct {
+ fn hash(v: *u32, key: anytype) void {
+ const Key = @TypeOf(key);
+ if (@typeInfo(Key) == .ErrorSet) {
+ v.* += 1;
+ return;
+ }
+ switch (@typeInfo(Key)) {
+ .ErrorUnion => blk: {
+ const payload = key catch |err| {
+ hash(v, err);
+ break :blk;
+ };
+
+ hash(v, payload);
+ },
+
+ else => unreachable,
+ }
+ }
+ };
+ const g: error{Test}!void = error.Test;
+
+ var v: u32 = 0;
+ S.hash(&v, g);
+ try expect(v == 1);
+}
+
+test "const inferred array of slices" {
+ const T = struct { v: bool };
+
+ const decls = [_][]const T{
+ &[_]T{
+ .{ .v = false },
+ },
+ };
+ _ = decls;
+}
+
+test "var inferred array of slices" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const T = struct { v: bool };
+
+ var decls = [_][]const T{
+ &[_]T{
+ .{ .v = false },
+ },
+ };
+ _ = &decls;
+}
+
+test "copy array of self-referential struct" {
+ const ListNode = struct {
+ next: ?*const @This() = null,
+ };
+ comptime var nodes = [_]ListNode{ .{}, .{} };
+ nodes[0].next = &nodes[1];
+ const copied_nodes = nodes;
+ _ = copied_nodes;
+}
+
+test "break out of block based on comptime known values" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ const source = "A-";
+
+ fn parseNote() ?i32 {
+ const letter = source[0];
+ const modifier = source[1];
+
+ const semitone = blk: {
+ if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
+ if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
+ if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
+ if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
+ if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
+ if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
+ if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
+ if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
+ if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
+ if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
+ if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
+ if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
+ return null;
+ };
+
+ return semitone;
+ }
+ };
+ const result = S.parseNote();
+ try std.testing.expect(result.? == 9);
+}
+
+test "allocation and looping over 3-byte integer" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
+ return error.SkipZigTest; // TODO
+ }
+
+ if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) {
+ return error.SkipZigTest; // TODO
+ }
+
+ try expect(@sizeOf(u24) == 4);
+ try expect(@sizeOf([1]u24) == 4);
+ try expect(@alignOf(u24) == 4);
+ try expect(@alignOf([1]u24) == 4);
+
+ var x = try std.testing.allocator.alloc(u24, 2);
+ defer std.testing.allocator.free(x);
+ try expect(x.len == 2);
+ x[0] = 0xFFFFFF;
+ x[1] = 0xFFFFFF;
+
+ const bytes = std.mem.sliceAsBytes(x);
+ try expect(@TypeOf(bytes) == []align(4) u8);
+ try expect(bytes.len == 8);
+
+ for (bytes) |*b| {
+ b.* = 0x00;
+ }
+
+ try expect(x[0] == 0x00);
+ try expect(x[1] == 0x00);
+}
test/behavior/bit_shifting.zig
@@ -152,3 +152,9 @@ test "Saturating Shift Left where lhs is of a computed type" {
try expect(value.value == 2);
try expect(value.exponent == 0);
}
+
+comptime {
+ var image: [1]u8 = undefined;
+ _ = ℑ
+ _ = @shlExact(@as(u16, image[0]), 8);
+}
test/behavior/bool.zig
@@ -90,3 +90,12 @@ fn testShortCircuit(f: bool, t: bool) !void {
try expect(hit_3);
try expect(hit_4);
}
+
+test "or with noreturn operand" {
+ const S = struct {
+ fn foo(a: u32, b: u32) bool {
+ return a == 5 or b == 2 or @panic("oh no");
+ }
+ };
+ _ = S.foo(2, 2);
+}
test/behavior/call.zig
@@ -520,3 +520,130 @@ test "call coerced function" {
const a = T{ .x = 3 };
try std.testing.expect(a.incr().x == 4);
}
+
+test "call function in comptime field" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ comptime capacity: fn () u64 = capacity_,
+ fn capacity_() u64 {
+ return 64;
+ }
+ };
+ try std.testing.expect((S{}).capacity() == 64);
+}
+
+test "call function pointer in comptime field" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Auto = struct {
+ auto: [max_len]u8 = undefined,
+ offset: u64 = 0,
+
+ comptime capacity: *const fn () u64 = capacity,
+
+ const max_len: u64 = 32;
+
+ fn capacity() u64 {
+ return max_len;
+ }
+ };
+
+ const a: Auto = .{ .offset = 16, .capacity = Auto.capacity };
+ try std.testing.expect(a.capacity() == 32);
+ try std.testing.expect((a.capacity)() == 32);
+}
+
+test "generic function pointer can be called" {
+ const S = struct {
+ var ok = false;
+ fn foo(x: anytype) void {
+ ok = x;
+ }
+ };
+ const x = &S.foo;
+ x(true);
+ try expect(S.ok);
+}
+
+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,
+ else => unreachable,
+ } {
+ return switch (@typeInfo(T)) {
+ .Struct => |info| info.fields,
+ else => unreachable,
+ };
+ }
+ };
+ const fields_list = S.fields(@TypeOf(.{}));
+ if (fields_list.len != 0)
+ @compileError("Argument count mismatch");
+}
+
+test "registers get overwritten when ignoring return" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest;
+
+ const S = struct {
+ fn open() usize {
+ return 42;
+ }
+ fn write(fd: usize, a: [*]const u8, len: usize) usize {
+ return syscall4(.WRITE, fd, @intFromPtr(a), len);
+ }
+ fn syscall4(_: enum { WRITE }, _: usize, _: usize, _: usize) usize {
+ return 23;
+ }
+ fn close(fd: usize) usize {
+ if (fd != 42)
+ unreachable;
+ return 0;
+ }
+ };
+
+ const fd = S.open();
+ _ = S.write(fd, "a", 1);
+ _ = S.close(fd);
+}
+
+test "call with union with zero sized field is not memorized incorrectly" {
+ const U = union(enum) {
+ T: type,
+ N: void,
+ fn S(comptime query: @This()) type {
+ return struct {
+ fn tag() type {
+ return query.T;
+ }
+ };
+ }
+ };
+ const s1 = U.S(U{ .T = u32 }).tag();
+ try std.testing.expectEqual(u32, s1);
+
+ const s2 = U.S(U{ .T = u64 }).tag();
+ try std.testing.expectEqual(u64, s2);
+}
+
+test "function call with cast to anyopaque pointer" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ const Foo = struct {
+ y: u8,
+ var foo: @This() = undefined;
+ const t = &foo;
+
+ fn bar(pointer: ?*anyopaque) void {
+ _ = pointer;
+ }
+ };
+ Foo.bar(Foo.t);
+}
test/behavior/cast.zig
@@ -2521,3 +2521,41 @@ test "result type is preserved into comptime block" {
const x: u32 = comptime @intCast(123);
try expect(x == 123);
}
+
+test "implicit cast from ptr to tuple to ptr to struct" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const ComptimeReason = union(enum) {
+ c_import: struct {
+ a: u32,
+ },
+ };
+
+ const Block = struct {
+ reason: ?*const ComptimeReason,
+ };
+
+ var a: u32 = 16;
+ _ = &a;
+ var reason = .{ .c_import = .{ .a = a } };
+ var block = Block{
+ .reason = &reason,
+ };
+ _ = █
+ try expect(block.reason.?.c_import.a == 16);
+}
+
+test "bitcast vector" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const u8x32 = @Vector(32, u8);
+ const u32x8 = @Vector(8, u32);
+
+ const zerox32: u8x32 = [_]u8{0} ** 32;
+ const bigsum: u32x8 = @bitCast(zerox32);
+ try std.testing.expectEqual(0, @reduce(.Add, bigsum));
+}
test/behavior/enum.zig
@@ -1235,3 +1235,10 @@ fn getLazyInitialized(param: enum(u8) {
}) u8 {
return @intFromEnum(param);
}
+
+test "Non-exhaustive enum backed by comptime_int" {
+ const E = enum(comptime_int) { a, b, c, _ };
+ comptime var e: E = .a;
+ e = @as(E, @enumFromInt(378089457309184723749));
+ try expect(@intFromEnum(e) == 378089457309184723749);
+}
test/behavior/error.zig
@@ -970,3 +970,59 @@ test "try used in recursive function with inferred error set" {
};
try expectError(error.a, Value.x(a));
}
+
+test "generic inline function returns inferred error set" {
+ const S = struct {
+ inline fn retErr(comptime T: type) !T {
+ return error.AnError;
+ }
+
+ fn main0() !void {
+ _ = try retErr(u8);
+ }
+ };
+ S.main0() catch |e| {
+ try std.testing.expect(e == error.AnError);
+ };
+}
+
+test "function called at runtime is properly analyzed for inferred error set" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn foo() !void {
+ var a = true;
+ _ = &a;
+ if (a) return error.Foo;
+ return error.Bar;
+ }
+ fn bar() !void {
+ try @This().foo();
+ }
+ };
+
+ S.bar() catch |err| switch (err) {
+ error.Foo => {},
+ error.Bar => {},
+ };
+}
+
+test "generic type constructed from inferred error set of unresolved function" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn write(_: void, bytes: []const u8) !usize {
+ _ = bytes;
+ return 0;
+ }
+ const T = std.io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write);
+ fn writer() T {
+ return .{ .context = {} };
+ }
+ };
+ _ = std.io.multiWriter(.{S.writer()});
+}
test/behavior/floatop.zig
@@ -1556,3 +1556,84 @@ test "comptime fixed-width float non-zero divided by zero produces signed Inf" {
test "comptime_float zero divided by zero produces zero" {
try expect((0.0 / 0.0) == 0.0);
}
+
+test "comptime float compared with runtime int" {
+ const f = 10.0;
+ var i: usize = 0;
+ _ = &i;
+ try std.testing.expect(i < f);
+}
+test "comptime nan < runtime 0" {
+ const f = comptime std.math.nan(f64);
+ var i: usize = 0;
+ _ = &i;
+ try std.testing.expect(!(f < i));
+}
+test "comptime inf > runtime 0" {
+ const f = comptime std.math.inf(f64);
+ var i: usize = 0;
+ _ = &i;
+ try std.testing.expect(f > i);
+}
+test "comptime -inf < runtime 0" {
+ const f = comptime -std.math.inf(f64);
+ var i: usize = 0;
+ _ = &i;
+ try std.testing.expect(f < i);
+}
+test "comptime inf >= runtime 1" {
+ const f = comptime std.math.inf(f64);
+ var i: usize = 1;
+ _ = &i;
+ try std.testing.expect(f >= i);
+}
+test "comptime isNan(nan * 1)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const nan_times_one = comptime std.math.nan(f64) * 1;
+ try std.testing.expect(std.math.isNan(nan_times_one));
+}
+test "runtime isNan(nan * 1)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const nan_times_one = std.math.nan(f64) * 1;
+ try std.testing.expect(std.math.isNan(nan_times_one));
+}
+test "comptime isNan(nan * 0)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const nan_times_zero = comptime std.math.nan(f64) * 0;
+ try std.testing.expect(std.math.isNan(nan_times_zero));
+ const zero_times_nan = 0 * comptime std.math.nan(f64);
+ try std.testing.expect(std.math.isNan(zero_times_nan));
+}
+test "runtime isNan(nan * 0)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const nan_times_zero = std.math.nan(f64) * 0;
+ try std.testing.expect(std.math.isNan(nan_times_zero));
+ const zero_times_nan = 0 * std.math.nan(f64);
+ try std.testing.expect(std.math.isNan(zero_times_nan));
+}
+test "comptime isNan(inf * 0)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const inf_times_zero = comptime std.math.inf(f64) * 0;
+ try std.testing.expect(std.math.isNan(inf_times_zero));
+ const zero_times_inf = 0 * comptime std.math.inf(f64);
+ try std.testing.expect(std.math.isNan(zero_times_inf));
+}
+test "runtime isNan(inf * 0)" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const inf_times_zero = std.math.inf(f64) * 0;
+ try std.testing.expect(std.math.isNan(inf_times_zero));
+ const zero_times_inf = 0 * std.math.inf(f64);
+ try std.testing.expect(std.math.isNan(zero_times_inf));
+}
test/behavior/for.zig
@@ -504,3 +504,24 @@ test "inferred alloc ptr of for loop" {
try expectEqual(@as(?bool, true), opt);
}
}
+
+test "for loop results in a bool" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ try std.testing.expect(for ([1]u8{0}) |x| {
+ if (x == 0) break true;
+ } else false);
+}
+
+test "return from inline for" {
+ const S = struct {
+ fn do() bool {
+ inline for (.{"a"}) |_| {
+ if (true) return false;
+ }
+ return true;
+ }
+ };
+ try std.testing.expect(!S.do());
+}
test/behavior/generics.zig
@@ -460,3 +460,101 @@ test "coerced function body has inequal value with its uncoerced body" {
};
try expect(S.A.do() == 1234);
}
+
+test "generic function returns value from callconv(.C) function" {
+ const S = struct {
+ fn getU8() callconv(.C) u8 {
+ return 123;
+ }
+
+ fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T {
+ return supplier();
+ }
+ };
+
+ try testing.expect(S.getGeneric(u8, S.getU8) == 123);
+}
+
+test "union in struct captures argument" {
+ const S = struct {
+ fn BuildType(comptime T: type) type {
+ return struct {
+ val: union {
+ b: T,
+ },
+ };
+ }
+ };
+ const TestStruct = S.BuildType(u32);
+ const c = TestStruct{ .val = .{ .b = 10 } };
+ try expect(c.val.b == 10);
+}
+
+test "function argument tuple used as struct field" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn DeleagateWithContext(comptime Function: type) type {
+ const ArgArgs = std.meta.ArgsTuple(Function);
+ return struct {
+ t: ArgArgs,
+ };
+ }
+
+ const OnConfirm = DeleagateWithContext(fn (bool) void);
+ const CustomDraw = DeleagateWithContext(fn (?OnConfirm) void);
+ };
+
+ var c: S.CustomDraw = undefined;
+ c.t[0] = null;
+ try expect(c.t[0] == null);
+}
+
+test "comptime callconv(.C) function ptr uses comptime type argument" {
+ const S = struct {
+ fn A(
+ comptime T: type,
+ comptime destroycb: ?*const fn (?*T) callconv(.C) void,
+ ) !void {
+ try expect(destroycb == null);
+ }
+ };
+ try S.A(u32, null);
+}
+
+test "call generic function with from function called by the generic function" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_llvm and
+ builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest;
+
+ const GET = struct {
+ key: []const u8,
+ const GET = @This();
+ const Redis = struct {
+ const Command = struct {
+ fn serialize(self: GET, comptime RootSerializer: type) void {
+ return RootSerializer.serializeCommand(.{ "GET", self.key });
+ }
+ };
+ };
+ };
+ const ArgSerializer = struct {
+ fn isCommand(comptime T: type) bool {
+ const tid = @typeInfo(T);
+ return (tid == .Struct or tid == .Enum or tid == .Union) and
+ @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
+ }
+ fn serializeCommand(command: anytype) void {
+ const CmdT = @TypeOf(command);
+
+ if (comptime isCommand(CmdT)) {
+ return CmdT.Redis.Command.serialize(command, @This());
+ }
+ }
+ };
+
+ ArgSerializer.serializeCommand(GET{ .key = "banana" });
+}
test/behavior/globals.zig
@@ -27,3 +27,22 @@ test "store to global vector" {
vpos = @Vector(2, f32){ 0.0, 1.0 };
try expect(vpos[1] == 1.0);
}
+
+test "slices pointing at the same address as global array." {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ const a = [_]u8{ 1, 2, 3 };
+
+ fn checkAddress(s: []const u8) !void {
+ for (s, 0..) |*i, j| {
+ try expect(i == &a[j]);
+ }
+ }
+ };
+
+ try S.checkAddress(&S.a);
+ try comptime S.checkAddress(&S.a);
+}
test/behavior/hasdecl.zig
@@ -19,3 +19,12 @@ test "@hasDecl" {
try expect(@hasDecl(Bar, "blah"));
try expect(!@hasDecl(Bar, "nope"));
}
+
+test "@hasDecl using a sliced string literal" {
+ try expect(@hasDecl(@This(), "std") == true);
+ try expect(@hasDecl(@This(), "std"[0..0]) == false);
+ try expect(@hasDecl(@This(), "std"[0..1]) == false);
+ try expect(@hasDecl(@This(), "std"[0..2]) == false);
+ try expect(@hasDecl(@This(), "std"[0..3]) == true);
+ try expect(@hasDecl(@This(), "std"[0..]) == true);
+}
test/behavior/if.zig
@@ -200,3 +200,11 @@ test "if value shouldn't be load-elided if used later (optionals)" {
try std.testing.expectEqual(c, 1);
}
+
+test "variable type inferred from if expression" {
+ var a = if (true) {
+ return;
+ } else true;
+ _ = &a;
+ return error.TestFailed;
+}
test/behavior/int_comparison_elision.zig
@@ -106,3 +106,8 @@ fn testIntEdges(comptime T: type) void {
if (undef_const == max + 1) @compileError("analyzed impossible branch");
if (undef_const != max + 1) {} else @compileError("analyzed impossible branch");
}
+
+test "comparison elided on large integer value" {
+ try std.testing.expect(-1 == @as(i8, -3) >> 2);
+ try std.testing.expect(-1 == -3 >> 2000);
+}
test/behavior/math.zig
@@ -164,6 +164,25 @@ fn testOneCtz(comptime T: type, x: T) u32 {
return @ctz(x);
}
+test "@ctz 128-bit integers" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ try testCtz128();
+ try comptime testCtz128();
+}
+
+fn testCtz128() !void {
+ try expect(testOneCtz(u128, @as(u128, 0x40000000000000000000000000000000)) == 126);
+ try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
+ try expect(testOneCtz(u128, @as(u128, 0x80000000000000000000000000000000)) == 127);
+ try expect(testOneCtz(u128, math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
+}
+
test "@ctz vectors" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
@@ -1700,3 +1719,21 @@ test "mod lazy values" {
_ = y;
}
}
+
+test "@clz works on both vector and scalar inputs" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ var x: u32 = 0x1;
+ _ = &x;
+ var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
+ _ = &y;
+ const a = @clz(x);
+ const b = @clz(y);
+ try std.testing.expectEqual(@as(u6, 31), a);
+ try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
+}
test/behavior/memset.zig
@@ -156,3 +156,23 @@ test "@memset provides result type" {
for (buf1) |s| try expect(s.x == 12);
for (buf2) |s| try expect(s.x == 34);
}
+
+test "zero keys with @memset" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Keys = struct {
+ up: bool,
+ down: bool,
+ left: bool,
+ right: bool,
+ var keys: @This() = undefined;
+ };
+ @memset(@as([*]u8, @ptrCast(&Keys.keys))[0..@sizeOf(@TypeOf(Keys.keys))], 0);
+ try expect(!Keys.keys.up);
+ try expect(!Keys.keys.down);
+ try expect(!Keys.keys.left);
+ try expect(!Keys.keys.right);
+}
test/behavior/bugs/529.zig โ test/behavior/multiple_externs_with_conflicting_types.zig
@@ -5,18 +5,18 @@ const A = extern struct {
extern fn issue529(?*A) void;
comptime {
- _ = @import("529_other_file_2.zig");
+ _ = @import("conflicting_externs/b.zig");
}
const builtin = @import("builtin");
-test "issue 529 fixed" {
+test "call extern function defined with conflicting type" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
- @import("529_other_file.zig").issue529(null);
+ @import("conflicting_externs/a.zig").issue529(null);
issue529(null);
}
test/behavior/optional.zig
@@ -495,3 +495,17 @@ test "variable of optional of noreturn" {
_ = &null_opv;
try std.testing.expectEqual(@as(?noreturn, null), null_opv);
}
+
+test "copied optional doesn't alias source" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ var opt_x: ?[3]f32 = [_]f32{0.0} ** 3;
+
+ const x = opt_x.?;
+ opt_x.?[0] = 15.0;
+
+ try expect(x[0] == 0.0);
+}
test/behavior/packed-struct.zig
@@ -1071,3 +1071,161 @@ test "assigning packed struct inside another packed struct" {
try expectEqual(val, S.mem.inner);
try expect(S.mem.padding == 0);
}
+
+test "packed struct used as part of anon decl name" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const S = packed struct { a: u0 = 0 };
+ var a: u8 = 0;
+ _ = &a;
+ try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
+}
+
+test "packed struct acts as a namespace" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const Bar = packed struct {
+ const Baz = enum {
+ fizz,
+ buzz,
+ };
+ };
+ var foo = Bar.Baz.fizz;
+ _ = &foo;
+ try expect(foo == .fizz);
+}
+
+test "pointer loaded correctly from packed struct" {
+ const RAM = struct {
+ data: [0xFFFF + 1]u8,
+ fn new() !@This() {
+ return .{ .data = [_]u8{0} ** 0x10000 };
+ }
+ fn get(self: *@This(), addr: u16) u8 {
+ return self.data[addr];
+ }
+ };
+
+ const CPU = packed struct {
+ interrupts: bool,
+ ram: *RAM,
+ fn new(ram: *RAM) !@This() {
+ return .{
+ .ram = ram,
+ .interrupts = false,
+ };
+ }
+ fn tick(self: *@This()) !void {
+ const queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);
+ if (self.interrupts and queued_interrupts != 0) {
+ self.interrupts = false;
+ }
+ }
+ };
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) {
+ // Careful enabling this test, fails randomly.
+ return error.SkipZigTest;
+ }
+
+ var ram = try RAM.new();
+ var cpu = try CPU.new(&ram);
+ try cpu.tick();
+ try std.testing.expect(cpu.interrupts == false);
+}
+
+test "assignment to non-byte-aligned field in packed struct" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Frame = packed struct {
+ num: u20,
+ };
+
+ const Entry = packed struct {
+ other: u12,
+ frame: Frame,
+ };
+
+ const frame = Frame{ .num = 0x7FDE };
+ var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
+ entry.frame = frame;
+ try expect(entry.frame.num == 0x7FDE);
+}
+
+test "packed struct field pointer aligned properly" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
+
+ const Foo = packed struct {
+ a: i32,
+ b: u8,
+
+ var buffer: [256]u8 = undefined;
+ };
+
+ var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&Foo.buffer[0])));
+ try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
+ try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
+ try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);
+}
+
+test "load flag from packed struct in union" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const A = packed struct {
+ a: bool,
+ b: bool,
+ c: bool,
+ d: bool,
+
+ e: bool,
+ f: bool,
+ g: bool,
+ h: bool,
+ };
+
+ const X = union {
+ x: A,
+ y: u64,
+
+ pub fn a(_: i32, _: i32, _: i32, _: i32, _: i32, _: bool, flag_b: bool) !void {
+ const flag_b_byte: u8 = @intFromBool(flag_b);
+ try std.testing.expect(flag_b_byte == 1);
+ }
+ pub fn b(x: *@This()) !void {
+ try a(0, 1, 2, 3, 4, x.x.a, x.x.b);
+ }
+ };
+ var flags = A{
+ .a = false,
+ .b = true,
+ .c = false,
+ .d = false,
+
+ .e = false,
+ .f = true,
+ .g = false,
+ .h = false,
+ };
+ _ = &flags;
+ var x = X{
+ .x = flags,
+ };
+ try X.b(&x);
+ comptime if (@sizeOf(A) != 1) unreachable;
+}
test/behavior/packed-union.zig
@@ -114,3 +114,31 @@ test "packed union in packed struct" {
try std.testing.expectEqual(RequestType.read, Request.init(.{ .key = 3 }).active_type);
}
+
+test "packed union initialized with a runtime value" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+
+ const Fields = packed struct {
+ timestamp: u50,
+ random_bits: u13,
+ };
+ const ID = packed union {
+ value: u63,
+ fields: Fields,
+
+ fn value() i64 {
+ return 1341;
+ }
+ };
+
+ const timestamp: i64 = ID.value();
+ const id = ID{ .fields = Fields{
+ .timestamp = @as(u50, @intCast(timestamp)),
+ .random_bits = 420,
+ } };
+ try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);
+}
test/behavior/pointers.zig
@@ -555,3 +555,68 @@ test "result type found through optional pointer" {
try expect(ptr2.?[0] == 123);
try expect(ptr2.?[1] == 0xCD);
}
+
+const Box0 = struct {
+ items: [4]Item,
+
+ const Item = struct {
+ num: u32,
+ };
+};
+const Box1 = struct {
+ items: [4]Item,
+
+ const Item = struct {};
+};
+const Box2 = struct {
+ items: [4]Item,
+
+ const Item = struct {
+ nothing: void,
+ };
+};
+
+fn mutable() !void {
+ var box0: Box0 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
+
+ var box1: Box1 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
+
+ var box2: Box2 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
+}
+
+fn constant() !void {
+ const box0: Box0 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
+
+ const box1: Box1 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
+
+ const box2: Box2 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
+}
+
+test "pointer-to-array constness for zero-size elements, var" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ try mutable();
+ try comptime mutable();
+}
+
+test "pointer-to-array constness for zero-size elements, const" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ try constant();
+ try comptime constant();
+}
+
+test "cast pointers with zero sized elements" {
+ const a: *void = undefined;
+ const b: *[1]void = a;
+ _ = b;
+ const c: *[0]u8 = undefined;
+ const d: []u8 = c;
+ _ = d;
+}
test/behavior/sizeof_and_typeof.zig
@@ -314,3 +314,117 @@ test "@bitSizeOf on array of structs" {
try expectEqual(128, @bitSizeOf([2]S));
}
+
+test "lazy abi size used in comparison" {
+ const S = struct { a: usize };
+ var rhs: i32 = 100;
+ _ = &rhs;
+ try expect(@sizeOf(S) < rhs);
+}
+
+test "peer type resolution with @TypeOf doesn't trigger dependency loop check" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const T = struct {
+ next: @TypeOf(null, @as(*const @This(), undefined)),
+ };
+ var t: T = .{ .next = null };
+ _ = &t;
+ try std.testing.expect(t.next == null);
+}
+
+test "@sizeOf reified union zero-size payload fields" {
+ comptime {
+ try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union {}))));
+ try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void }))));
+ if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) {
+ try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void }))));
+ try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void }))));
+ } else {
+ try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void }))));
+ try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void }))));
+ }
+ }
+}
+
+const FILE = extern struct {
+ dummy_field: u8,
+};
+
+extern fn c_printf([*c]const u8, ...) c_int;
+extern fn c_fputs([*c]const u8, noalias [*c]FILE) c_int;
+extern fn c_ftell([*c]FILE) c_long;
+extern fn c_fopen([*c]const u8, [*c]const u8) [*c]FILE;
+
+test "Extern function calls in @TypeOf" {
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const S = extern struct {
+ state: c_short,
+
+ extern fn s_do_thing([*c]const @This(), b: c_int) c_short;
+ };
+
+ const Test = struct {
+ fn test_fn_1(a: anytype, b: anytype) @TypeOf(c_printf("%d %s\n", a, b)) {
+ return 0;
+ }
+
+ fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) {
+ return 1;
+ }
+
+ fn doTheTest() !void {
+ try expect(@TypeOf(test_fn_1(0, 42)) == c_int);
+ try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short);
+ }
+ };
+
+ try Test.doTheTest();
+ try comptime Test.doTheTest();
+}
+
+test "Peer resolution of extern function calls in @TypeOf" {
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Test = struct {
+ fn test_fn() @TypeOf(c_ftell(null), c_fputs(null, null)) {
+ return 0;
+ }
+
+ fn doTheTest() !void {
+ try expect(@TypeOf(test_fn()) == c_long);
+ }
+ };
+
+ try Test.doTheTest();
+ try comptime Test.doTheTest();
+}
+
+test "Extern function calls, dereferences and field access in @TypeOf" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Test = struct {
+ fn test_fn_1(a: c_long) @TypeOf(c_fopen("test", "r").*) {
+ _ = a;
+ return .{ .dummy_field = 0 };
+ }
+
+ fn test_fn_2(a: anytype) @TypeOf(c_fopen("test", "r").*.dummy_field) {
+ _ = a;
+ return 255;
+ }
+
+ fn doTheTest() !void {
+ try expect(@TypeOf(test_fn_1(0)) == FILE);
+ try expect(@TypeOf(test_fn_2(0)) == u8);
+ }
+ };
+
+ try Test.doTheTest();
+ try comptime Test.doTheTest();
+}
test/behavior/slice.zig
@@ -912,3 +912,67 @@ test "modify slice length at comptime" {
try expectEqualSlices(u8, &.{10}, a);
try expectEqualSlices(u8, &.{ 10, 20 }, b);
}
+
+test "slicing zero length array field of struct" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const S = struct {
+ a: [0]usize,
+ fn foo(self: *@This(), start: usize, end: usize) []usize {
+ return self.a[start..end];
+ }
+ };
+ var s: S = undefined;
+ try expect(s.foo(0, 0).len == 0);
+}
+
+test "slicing slices gives correct result" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const foo = "1234";
+ const bar = foo[0..4];
+ try expectEqualStrings("1234", bar);
+ try expectEqualStrings("2", bar[1..2]);
+ try expectEqualStrings("3", bar[2..3]);
+ try expectEqualStrings("4", bar[3..4]);
+ try expectEqualStrings("34", bar[2..4]);
+}
+
+test "get address of element of zero-sized slice" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn destroy(_: *void) void {}
+ };
+
+ var slice: []void = undefined;
+ S.destroy(&slice[0]);
+}
+
+test "sentinel-terminated 0-length slices" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
+
+ var index: u8 = 2;
+ _ = &index;
+ const slice = u32s[index..index :2];
+ const array_ptr = u32s[2..2 :2];
+ const comptime_known_array_value = u32s[2..2 :2].*;
+ var runtime_array_value = u32s[2..2 :2].*;
+ _ = &runtime_array_value;
+
+ try expect(slice[0] == 2);
+ try expect(array_ptr[0] == 2);
+ try expect(comptime_known_array_value[0] == 2);
+ try expect(runtime_array_value[0] == 2);
+}
test/behavior/string_literals.zig
@@ -80,3 +80,19 @@ test "string literal pointer sentinel" {
try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8);
}
+
+test "sentinel slice of string literal" {
+ const string = "Hello!\x00World!";
+ try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
+
+ const slice_without_sentinel: []const u8 = string[0..6];
+ try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
+
+ const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
+ try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
+}
+
+test "Peer type resolution with string literals and unknown length u8 pointers" {
+ try std.testing.expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
+ try std.testing.expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
+}
test/behavior/struct.zig
@@ -203,18 +203,18 @@ test "return struct byval from function" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- const bar = makeBar2(1234, 5678);
- try expect(bar.y == 5678);
-}
-const Bar = struct {
- x: i32,
- y: i32,
-};
-fn makeBar2(x: i32, y: i32) Bar {
- return Bar{
- .x = x,
- .y = y,
+ const Bar = struct {
+ x: i32,
+ y: i32,
+ fn makeBar2(x: i32, y: i32) @This() {
+ return .{
+ .x = x,
+ .y = y,
+ };
+ }
};
+ const bar = Bar.makeBar2(1234, 5678);
+ try expect(bar.y == 5678);
}
test "call method with mutable reference to struct with no fields" {
@@ -1883,10 +1883,234 @@ test "field calls do not force struct field init resolution" {
}
test "tuple with comptime-only field" {
- const x = getTuple();
+ const S = struct {
+ fn getTuple() struct { comptime_int } {
+ return struct { comptime comptime_int = 0 }{0};
+ }
+ };
+
+ const x = S.getTuple();
try expect(x.@"0" == 0);
}
-fn getTuple() struct { comptime_int } {
- return struct { comptime comptime_int = 0 }{0};
+test "extern struct fields are aligned to 1" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const Foo = extern struct {
+ a: u8 align(1),
+ b: u16 align(1),
+ };
+
+ const foo = Foo{
+ .a = 1,
+ .b = 2,
+ };
+ try std.testing.expectEqual(1, foo.a);
+ try std.testing.expectEqual(2, foo.b);
+}
+
+test "assign to slice.len of global variable" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const S = struct {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u32).init(allocator);
+ };
+
+ S.list.items.len = 0;
+ try expect(S.list.items.len == 0);
+}
+
+test "pointers to fields of volatile pointer to struct are also volatile" {
+ const B = extern struct {
+ a: u32,
+ b: i32,
+ };
+ const A = extern struct {
+ value: *volatile B,
+ };
+
+ var a: *A = undefined;
+ try expect(@TypeOf(&a.value.a) == *volatile u32);
+ try expect(@TypeOf(&a.value.b) == *volatile i32);
+}
+
+test "pointers to fields of volatile pointer to union are also volatile" {
+ const D = extern union {
+ a: u32,
+ b: i32,
+ };
+ const C = extern struct {
+ value: *volatile D,
+ };
+
+ var c: *C = undefined;
+ try expect(@TypeOf(&c.value.a) == *volatile u32);
+ try expect(@TypeOf(&c.value.b) == *volatile i32);
+}
+
+test "array of structs inside struct initialized with undefined" {
+ const Item = struct { field: u8 };
+ const Thing = struct {
+ array: [1]Item,
+ };
+ _ = Thing{ .array = undefined };
+}
+
+test "runtime call in nested initializer" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const Holder = struct {
+ array: []const u8,
+ };
+ const Test = struct {
+ holders: []const Holder,
+ };
+ const Letter = enum(u8) {
+ A = 0x41,
+ B,
+
+ fn letter(e: @This()) u8 {
+ return @intFromEnum(e);
+ }
+ };
+
+ const test_struct = Test{
+ .holders = &.{
+ Holder{
+ .array = &.{
+ Letter.letter(.A),
+ },
+ },
+ },
+ };
+ try std.testing.expectEqualStrings("A", test_struct.holders[0].array);
+}
+
+test "runtime value in nested initializer passed as pointer to function" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const Bar = struct {
+ b: u32,
+ };
+ const Foo = struct {
+ a: Bar,
+
+ fn takeFoo(foo: *const @This()) !void {
+ try std.testing.expectEqual(@as(u32, 24), foo.a.b);
+ }
+ };
+
+ var baz: u32 = 24;
+ _ = &baz;
+ try Foo.takeFoo(&.{
+ .a = .{
+ .b = baz,
+ },
+ });
+}
+
+test "struct field default value is a call" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const Z = packed struct {
+ a: u32,
+ };
+ const Y = struct {
+ a: u16,
+ b: bool,
+ c: Z,
+ d: Z,
+
+ fn init() @This() {
+ return .{
+ .a = 0,
+ .b = false,
+ .c = @as(Z, @bitCast(@as(u32, 0))),
+ .d = @as(Z, @bitCast(@as(u32, 0))),
+ };
+ }
+ };
+ const X = struct {
+ y: Y = Y.init(),
+ };
+
+ const x = X{};
+ try std.testing.expectEqual(@as(u16, 0), x.y.a);
+ try std.testing.expectEqual(false, x.y.b);
+ try std.testing.expectEqual(Z{ .a = 0 }, x.y.c);
+ try std.testing.expectEqual(Z{ .a = 0 }, x.y.d);
+}
+
+test "aggregate initializers should allow initializing comptime fields, verifying equality" {
+ var x: u32 = 15;
+ _ = &x;
+ const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
+ const a: T = .{ -1234, 5678, x + 1 };
+
+ try expect(a[0] == -1234);
+ try expect(a[1] == 5678);
+ try expect(a[2] == 16);
+}
+
+test "assignment of field with padding" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const Mesh = extern struct {
+ id: u32,
+ };
+ const Material = extern struct {
+ transparent: bool = true,
+ emits_shadows: bool = true,
+ render_color: bool = true,
+ };
+ const Renderable = extern struct {
+ material: Material,
+ mesh: Mesh,
+ };
+ var renderable: Renderable = undefined;
+ renderable = Renderable{
+ .mesh = Mesh{ .id = 0 },
+ .material = Material{
+ .transparent = false,
+ .emits_shadows = false,
+ },
+ };
+ try expect(false == renderable.material.transparent);
+ try expect(false == renderable.material.emits_shadows);
+ try expect(true == renderable.material.render_color);
+}
+
+test "initiate global variable with runtime value" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ field: i32,
+ fn couldFail() anyerror!i32 {
+ return 1;
+ }
+ var some_struct: @This() = undefined;
+ };
+
+ S.some_struct = .{
+ .field = S.couldFail() catch 0,
+ };
+ try expect(S.some_struct.field == 1);
}
test/behavior/switch.zig
@@ -831,3 +831,22 @@ test "peer type resolution on switch captures ignores unused payload bits" {
try expect(x == 123);
}
+
+test "switch prong captures range" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn a(b: []u3, c: u3) void {
+ switch (c) {
+ 0...1 => b[c] = c,
+ 2...3 => b[c] = c,
+ 4...7 => |d| b[d] = c,
+ }
+ }
+ };
+
+ var arr: [8]u3 = undefined;
+ S.a(&arr, 5);
+ try expect(arr[5] == 5);
+}
test/behavior/this.zig
@@ -35,3 +35,23 @@ test "this refer to container" {
try expect(pt.x == 13);
try expect(pt.y == 35);
}
+
+const State = struct {
+ const Self = @This();
+ enter: *const fn (previous: ?Self) void,
+};
+
+fn prev(p: ?State) void {
+ expect(p == null) catch @panic("test failure");
+}
+
+test "this used as optional function parameter" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ var global: State = undefined;
+ global.enter = prev;
+ global.enter(null);
+}
test/behavior/try.zig
@@ -45,3 +45,24 @@ test "try then not executed with assignment" {
try expect(err == error.ItBroke);
}
}
+
+test "`try`ing an if/else expression" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const S = struct {
+ fn getError() !void {
+ return error.Test;
+ }
+
+ fn getError2() !void {
+ var a: u8 = 'c';
+ _ = &a;
+ try if (a == 'a') getError() else if (a == 'b') getError() else getError();
+ }
+ };
+
+ try std.testing.expectError(error.Test, S.getError2());
+}
test/behavior/tuple.zig
@@ -488,3 +488,76 @@ test "tuple with comptime fields with non empty initializer" {
const a: struct { comptime comptime_int = 0 } = .{0};
_ = a;
}
+
+test "tuple with runtime value coerced into a slice with a sentinel" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn f(a: [:null]const ?u8) !void {
+ try expect(a[0] == 42);
+ }
+ };
+
+ const c: u8 = 42;
+ try S.f(&[_:null]?u8{c});
+ try S.f(&.{c});
+
+ var v: u8 = 42;
+ _ = &v;
+ try S.f(&[_:null]?u8{v});
+ try S.f(&.{v});
+}
+
+test "tuple implicitly coerced to optional/error union struct/union" {
+ const SomeUnion = union(enum) {
+ variant: u8,
+ };
+ const SomeStruct = struct {
+ struct_field: u8,
+ };
+ const OptEnum = struct {
+ opt_union: ?SomeUnion,
+ };
+ const ErrEnum = struct {
+ err_union: anyerror!SomeUnion,
+ };
+ const OptStruct = struct {
+ opt_struct: ?SomeStruct,
+ };
+ const ErrStruct = struct {
+ err_struct: anyerror!SomeStruct,
+ };
+
+ try expect((OptEnum{
+ .opt_union = .{
+ .variant = 1,
+ },
+ }).opt_union.?.variant == 1);
+
+ try expect(((ErrEnum{
+ .err_union = .{
+ .variant = 1,
+ },
+ }).err_union catch unreachable).variant == 1);
+
+ try expect((OptStruct{
+ .opt_struct = .{
+ .struct_field = 1,
+ },
+ }).opt_struct.?.struct_field == 1);
+
+ try expect(((ErrStruct{
+ .err_struct = .{
+ .struct_field = 1,
+ },
+ }).err_struct catch unreachable).struct_field == 1);
+}
+
+test "comptime fields in tuple can be initialized" {
+ const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
+ var a: T = .{ 0, 0 };
+ _ = &a;
+}
test/behavior/type.zig
@@ -568,3 +568,169 @@ test "reified struct field name from optional payload" {
}
}
}
+
+test "reified union uses @alignOf" {
+ const S = struct {
+ fn CreateUnion(comptime T: type) type {
+ return @Type(.{
+ .Union = .{
+ .layout = .Auto,
+ .tag_type = null,
+ .fields = &[_]std.builtin.Type.UnionField{
+ .{
+ .name = "field",
+ .type = T,
+ .alignment = @alignOf(T),
+ },
+ },
+ .decls = &.{},
+ },
+ });
+ }
+ };
+ _ = S.CreateUnion(struct {});
+}
+
+test "reified struct uses @alignOf" {
+ const S = struct {
+ fn NamespacedGlobals(comptime modules: anytype) type {
+ return @Type(.{
+ .Struct = .{
+ .layout = .Auto,
+ .is_tuple = false,
+ .fields = &.{
+ .{
+ .name = "globals",
+ .type = modules.mach.globals,
+ .default_value = null,
+ .is_comptime = false,
+ .alignment = @alignOf(modules.mach.globals),
+ },
+ },
+ .decls = &.{},
+ },
+ });
+ }
+ };
+ _ = S.NamespacedGlobals(.{
+ .mach = .{
+ .globals = struct {},
+ },
+ });
+}
+
+test "reified error set initialized with field pointer" {
+ const S = struct {
+ const info = .{
+ .args = [_]Type.Error{
+ .{ .name = "bar" },
+ },
+ };
+ const Foo = @Type(.{
+ .ErrorSet = &info.args,
+ });
+ };
+ try testing.expect(S.Foo == error{bar});
+}
+test "reified function type params initialized with field pointer" {
+ const S = struct {
+ const fn_info = .{
+ .params = [_]Type.Fn.Param{
+ .{ .is_generic = false, .is_noalias = false, .type = u8 },
+ },
+ };
+ const Bar = @Type(.{
+ .Fn = .{
+ .calling_convention = .Unspecified,
+ .alignment = 0,
+ .is_generic = false,
+ .is_var_args = false,
+ .return_type = void,
+ .params = &fn_info.params,
+ },
+ });
+ };
+ try testing.expect(@typeInfo(S.Bar) == .Fn);
+}
+
+test "empty struct assigned to reified struct field" {
+ const S = struct {
+ fn NamespacedComponents(comptime modules: anytype) type {
+ return @Type(.{
+ .Struct = .{
+ .layout = .Auto,
+ .is_tuple = false,
+ .fields = &.{.{
+ .name = "components",
+ .type = @TypeOf(modules.components),
+ .default_value = null,
+ .is_comptime = false,
+ .alignment = @alignOf(@TypeOf(modules.components)),
+ }},
+ .decls = &.{},
+ },
+ });
+ }
+
+ fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) {
+ var x: NamespacedComponents(modules) = undefined;
+ x.components = modules.components;
+ return x;
+ }
+ };
+ _ = S.namespacedComponents(.{
+ .components = .{
+ .location = struct {},
+ },
+ });
+}
+
+test "@Type should resolve its children types" {
+ const sparse = enum(u2) { a, b, c };
+ const dense = enum(u2) { a, b, c, d };
+
+ comptime var sparse_info = @typeInfo(anyerror!sparse);
+ sparse_info.ErrorUnion.payload = dense;
+ const B = @Type(sparse_info);
+ try testing.expectEqual(anyerror!dense, B);
+}
+
+test "struct field names sliced at comptime from larger string" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const text =
+ \\f1
+ \\f2
+ \\f3
+ ;
+ comptime {
+ var fields: []const Type.StructField = &[0]Type.StructField{};
+
+ var it = std.mem.tokenizeScalar(u8, text, '\n');
+ while (it.next()) |name| {
+ fields = fields ++ &[_]Type.StructField{.{
+ .alignment = 0,
+ .name = name,
+ .type = usize,
+ .default_value = null,
+ .is_comptime = false,
+ }};
+ }
+
+ const T = @Type(.{
+ .Struct = .{
+ .layout = .Auto,
+ .is_tuple = false,
+ .fields = fields,
+ .decls = &.{},
+ },
+ });
+
+ const gen_fields = @typeInfo(T).Struct.fields;
+ try testing.expectEqual(3, gen_fields.len);
+ try testing.expectEqualStrings("f1", gen_fields[0].name);
+ try testing.expectEqualStrings("f2", gen_fields[1].name);
+ try testing.expectEqualStrings("f3", gen_fields[2].name);
+ }
+}
test/behavior/undefined.zig
@@ -84,3 +84,16 @@ test "type name of undefined" {
const x = undefined;
try expect(mem.eql(u8, @typeName(@TypeOf(x)), "@TypeOf(undefined)"));
}
+
+var buf: []u8 = undefined;
+
+test "reslice of undefined global var slice" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ var stack_buf: [100]u8 = [_]u8{0} ** 100;
+ buf = &stack_buf;
+ const x = buf[0..1];
+ try @import("std").testing.expect(x.len == 1 and x[0] == 0);
+}
test/behavior/union.zig
@@ -2112,3 +2112,143 @@ test "pass nested union with rls" {
_ = &c;
try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } }));
}
+
+test "runtime union init, most-aligned field != largest" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ const U = union(enum) {
+ x: u128,
+ y: [17]u8,
+
+ fn foo(val: @This()) !void {
+ try expect(val.x == 1);
+ }
+ };
+ var x: u8 = 1;
+ _ = &x;
+ try U.foo(.{ .x = x });
+
+ const val: U = @unionInit(U, "x", x);
+ try expect(val.x == 1);
+
+ const val2: U = .{ .x = x };
+ try expect(val2.x == 1);
+}
+
+test "copied union field doesn't alias source" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const U = union(enum) {
+ array: [10]u32,
+ other: u32,
+ };
+
+ var x = U{ .array = undefined };
+
+ x.array[1] = 0;
+ const a = x.array;
+ x.array[1] = 15;
+
+ try expect(a[1] == 0);
+}
+
+test "create union(enum) from other union(enum)" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const string = "hello world";
+ const TempRef = struct {
+ index: usize,
+ is_weak: bool,
+ };
+ const BuiltinEnum = struct {
+ name: []const u8,
+ };
+ const ParamType = union(enum) {
+ boolean,
+ buffer,
+ one_of: BuiltinEnum,
+ };
+ const EnumLiteral = struct {
+ label: []const u8,
+ };
+
+ const ExpressionResult = union(enum) {
+ temp_buffer: TempRef,
+ literal_boolean: bool,
+ literal_enum_value: []const u8,
+
+ fn commitCalleeParam(result: @This(), callee_param_type: ParamType) @This() {
+ switch (callee_param_type) {
+ .boolean => return result,
+ .buffer => return .{
+ .temp_buffer = .{ .index = 0, .is_weak = false },
+ },
+ .one_of => return result,
+ }
+ }
+ };
+ const Expression = union(enum) {
+ literal_boolean: bool,
+ literal_enum_value: EnumLiteral,
+
+ fn genExpression(expr: @This()) !ExpressionResult {
+ switch (expr) {
+ .literal_boolean => |value| return .{
+ .literal_boolean = value,
+ },
+ .literal_enum_value => |v| {
+ try std.testing.expectEqualStrings(string, v.label);
+ const result: ExpressionResult = .{
+ .literal_enum_value = v.label,
+ };
+ switch (result) {
+ .literal_enum_value => |w| {
+ try std.testing.expectEqualStrings(string, w);
+ },
+ else => {},
+ }
+ return result;
+ },
+ }
+ }
+ };
+ const CallArg = struct {
+ value: Expression,
+ };
+
+ var param: ParamType = .{
+ .one_of = .{ .name = "name" },
+ };
+ _ = ¶m;
+ var arg: CallArg = .{
+ .value = .{
+ .literal_enum_value = .{
+ .label = string,
+ },
+ },
+ };
+ _ = &arg;
+
+ const result = try arg.value.genExpression();
+ switch (result) {
+ .literal_enum_value => |w| {
+ try std.testing.expectEqualStrings(string, w);
+ },
+ else => {},
+ }
+
+ const derp = result.commitCalleeParam(param);
+ switch (derp) {
+ .literal_enum_value => |w| {
+ try std.testing.expectEqualStrings(string, w);
+ },
+ else => {},
+ }
+}
test/behavior/usingnamespace.zig
@@ -82,3 +82,18 @@ test {
comptime {
_ = @import("usingnamespace/file_1.zig");
}
+
+const Bar = struct {
+ usingnamespace Mixin;
+};
+
+const Mixin = struct {
+ pub fn two(self: Bar) void {
+ _ = self;
+ }
+};
+
+test "container member access usingnamespace decls" {
+ var foo = Bar{};
+ foo.two();
+}
test/behavior/vector.zig
@@ -1530,3 +1530,39 @@ test "index into comptime-known vector is comptime-known" {
const vec: @Vector(2, f16) = [2]f16{ 1.5, 3.5 };
if (vec[0] != 1.5) @compileError("vec should be comptime");
}
+
+test "arithmetic on zero-length vectors" {
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ {
+ const a = @Vector(0, i32){};
+ const b = @Vector(0, i32){};
+ _ = a + b;
+ }
+ {
+ const a = @Vector(0, i32){};
+ const b = @Vector(0, i32){};
+ _ = a - b;
+ }
+}
+
+test "@reduce on bool vector" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) {
+ // https://github.com/ziglang/zig/issues/13782
+ return error.SkipZigTest;
+ }
+
+ const a = @Vector(2, bool){ true, true };
+ const b = @Vector(1, bool){true};
+ try std.testing.expect(@reduce(.And, a));
+ try std.testing.expect(@reduce(.And, b));
+}
test/behavior/while.zig
@@ -367,3 +367,37 @@ test "while loop with comptime true condition needs no else block to return valu
};
try expect(x == 69);
}
+
+test "int returned from switch in while" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ var x: u32 = 3;
+ const val: usize = while (true) switch (x) {
+ 1 => break 2,
+ else => x -= 1,
+ };
+ try std.testing.expect(val == 2);
+}
+
+test "breaking from a loop in an if statement" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn retOpt() ?u32 {
+ return null;
+ }
+ };
+
+ var cond = true;
+ _ = &cond;
+ const opt = while (cond) {
+ if (S.retOpt()) |opt| {
+ break opt;
+ }
+ break 1;
+ } else 2;
+ _ = opt;
+}
test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig
@@ -1,5 +1,5 @@
const Foo = extern struct {
- f: *const fn() void,
+ f: *const fn () void,
};
export fn entry() void {
test/cases/compile_errors/invalid_extern_function_call.zig
@@ -1,4 +1,4 @@
-const x = @extern(*const fn() callconv(.C) void, .{ .name = "foo" });
+const x = @extern(*const fn () callconv(.C) void, .{ .name = "foo" });
export fn entry0() void {
comptime x();
test/behavior.zig
@@ -12,136 +12,6 @@ test {
_ = @import("behavior/bitcast.zig");
_ = @import("behavior/bitreverse.zig");
_ = @import("behavior/bool.zig");
- // Ideally, all tests would be categorized and independent from GitHub, but
- // if that's too much trouble, having test coverage this way is better than nothing.
- _ = @import("behavior/bugs/394.zig");
- _ = @import("behavior/bugs/421.zig");
- _ = @import("behavior/bugs/529.zig");
- _ = @import("behavior/bugs/624.zig");
- _ = @import("behavior/bugs/655.zig");
- _ = @import("behavior/bugs/656.zig");
- _ = @import("behavior/bugs/679.zig");
- _ = @import("behavior/bugs/704.zig");
- _ = @import("behavior/bugs/718.zig");
- _ = @import("behavior/bugs/726.zig");
- _ = @import("behavior/bugs/828.zig");
- _ = @import("behavior/bugs/920.zig");
- _ = @import("behavior/bugs/1025.zig");
- _ = @import("behavior/bugs/1076.zig");
- _ = @import("behavior/bugs/1277.zig");
- _ = @import("behavior/bugs/1310.zig");
- _ = @import("behavior/bugs/1381.zig");
- _ = @import("behavior/bugs/1421.zig");
- _ = @import("behavior/bugs/1442.zig");
- _ = @import("behavior/bugs/1486.zig");
- _ = @import("behavior/bugs/1500.zig");
- _ = @import("behavior/bugs/1607.zig");
- _ = @import("behavior/bugs/1735.zig");
- _ = @import("behavior/bugs/1851.zig");
- _ = @import("behavior/bugs/1914.zig");
- _ = @import("behavior/bugs/2006.zig");
- _ = @import("behavior/bugs/2114.zig");
- _ = @import("behavior/bugs/2346.zig");
- _ = @import("behavior/bugs/2557.zig");
- _ = @import("behavior/bugs/2578.zig");
- _ = @import("behavior/bugs/2622.zig");
- _ = @import("behavior/bugs/2692.zig");
- _ = @import("behavior/bugs/2727.zig");
- _ = @import("behavior/bugs/2889.zig");
- _ = @import("behavior/bugs/3007.zig");
- _ = @import("behavior/bugs/3046.zig");
- _ = @import("behavior/bugs/3112.zig");
- _ = @import("behavior/bugs/3367.zig");
- _ = @import("behavior/bugs/3384.zig");
- _ = @import("behavior/bugs/3586.zig");
- _ = @import("behavior/bugs/3742.zig");
- _ = @import("behavior/bugs/4328.zig");
- _ = @import("behavior/bugs/4560.zig");
- _ = @import("behavior/bugs/4769_a.zig");
- _ = @import("behavior/bugs/4769_b.zig");
- _ = @import("behavior/bugs/4954.zig");
- _ = @import("behavior/bugs/5398.zig");
- _ = @import("behavior/bugs/5413.zig");
- _ = @import("behavior/bugs/5474.zig");
- _ = @import("behavior/bugs/5487.zig");
- _ = @import("behavior/bugs/6047.zig");
- _ = @import("behavior/bugs/6456.zig");
- _ = @import("behavior/bugs/6781.zig");
- _ = @import("behavior/bugs/6850.zig");
- _ = @import("behavior/bugs/6905.zig");
- _ = @import("behavior/bugs/6947.zig");
- _ = @import("behavior/bugs/7003.zig");
- _ = @import("behavior/bugs/7047.zig");
- _ = @import("behavior/bugs/7187.zig");
- _ = @import("behavior/bugs/7325.zig");
- _ = @import("behavior/bugs/8277.zig");
- _ = @import("behavior/bugs/8646.zig");
- _ = @import("behavior/bugs/9584.zig");
- _ = @import("behavior/bugs/10138.zig");
- _ = @import("behavior/bugs/10147.zig");
- _ = @import("behavior/bugs/10970.zig");
- _ = @import("behavior/bugs/10684.zig");
- _ = @import("behavior/bugs/11046.zig");
- _ = @import("behavior/bugs/11100.zig");
- _ = @import("behavior/bugs/11139.zig");
- _ = @import("behavior/bugs/11159.zig");
- _ = @import("behavior/bugs/11162.zig");
- _ = @import("behavior/bugs/11165.zig");
- _ = @import("behavior/bugs/11179.zig");
- _ = @import("behavior/bugs/11181.zig");
- _ = @import("behavior/bugs/11213.zig");
- _ = @import("behavior/bugs/11787.zig");
- _ = @import("behavior/bugs/11816.zig");
- _ = @import("behavior/bugs/11995.zig");
- _ = @import("behavior/bugs/12000.zig");
- _ = @import("behavior/bugs/12003.zig");
- _ = @import("behavior/bugs/12025.zig");
- _ = @import("behavior/bugs/12033.zig");
- _ = @import("behavior/bugs/12043.zig");
- _ = @import("behavior/bugs/12051.zig");
- _ = @import("behavior/bugs/12092.zig");
- _ = @import("behavior/bugs/12119.zig");
- _ = @import("behavior/bugs/12142.zig");
- _ = @import("behavior/bugs/12169.zig");
- _ = @import("behavior/bugs/12430.zig");
- _ = @import("behavior/bugs/12450.zig");
- _ = @import("behavior/bugs/12486.zig");
- _ = @import("behavior/bugs/12498.zig");
- _ = @import("behavior/bugs/12551.zig");
- _ = @import("behavior/bugs/12571.zig");
- _ = @import("behavior/bugs/12644.zig");
- _ = @import("behavior/bugs/12723.zig");
- _ = @import("behavior/bugs/12776.zig");
- _ = @import("behavior/bugs/12786.zig");
- _ = @import("behavior/bugs/12794.zig");
- _ = @import("behavior/bugs/12801-1.zig");
- _ = @import("behavior/bugs/12801-2.zig");
- _ = @import("behavior/bugs/12885.zig");
- _ = @import("behavior/bugs/12890.zig");
- _ = @import("behavior/bugs/12891.zig");
- _ = @import("behavior/bugs/12911.zig");
- _ = @import("behavior/bugs/12928.zig");
- _ = @import("behavior/bugs/12945.zig");
- _ = @import("behavior/bugs/12972.zig");
- _ = @import("behavior/bugs/12984.zig");
- _ = @import("behavior/bugs/13064.zig");
- _ = @import("behavior/bugs/13065.zig");
- _ = @import("behavior/bugs/13068.zig");
- _ = @import("behavior/bugs/13069.zig");
- _ = @import("behavior/bugs/13112.zig");
- _ = @import("behavior/bugs/13113.zig");
- _ = @import("behavior/bugs/13128.zig");
- _ = @import("behavior/bugs/13159.zig");
- _ = @import("behavior/bugs/13171.zig");
- _ = @import("behavior/bugs/13209.zig");
- _ = @import("behavior/bugs/13285.zig");
- _ = @import("behavior/bugs/13366.zig");
- _ = @import("behavior/bugs/13435.zig");
- _ = @import("behavior/bugs/13664.zig");
- _ = @import("behavior/bugs/13714.zig");
- _ = @import("behavior/bugs/13785.zig");
- _ = @import("behavior/bugs/14854.zig");
- _ = @import("behavior/bugs/15778.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/c_char_signedness.zig");
@@ -189,6 +59,7 @@ test {
_ = @import("behavior/memset.zig");
_ = @import("behavior/merge_error_sets.zig");
_ = @import("behavior/muladd.zig");
+ _ = @import("behavior/multiple_externs_with_conflicting_types.zig");
_ = @import("behavior/namespace_depends_on_compile_var.zig");
_ = @import("behavior/nan.zig");
_ = @import("behavior/null.zig");