authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-28 12:58:55+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-28 15:24:01+02:00
log60614b2a854df0732d0d215a236cf051afd4f832
tree25de4b172d6a6215c376f796f7542f7ec40ab562
parent0588595128c4534e3a6bc207d446b66032d5720c

add tests for fixed stage1 bugs

Closes #10357 Closes #11236 Closes #11615 Closes #12055

5 files changed, 56 insertions(+), 21 deletions(-)

test/behavior/error.zig+10
......@@ -930,6 +930,16 @@ test "optional error set return type" {
930930 try expect(E.A == S.foo(false).?);
931931}
932932
933test "optional error set function parameter" {
934 const S = struct {
935 fn doTheTest(a: ?anyerror) !void {
936 try std.testing.expect(a.? == error.OutOfMemory);
937 }
938 };
939 try S.doTheTest(error.OutOfMemory);
940 try comptime S.doTheTest(error.OutOfMemory);
941}
942
933943test "returning an error union containing a type with no runtime bits" {
934944 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
935945 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
test/cases/compile_errors/error_union_field_default_init.zig created+13
......@@ -0,0 +1,13 @@
1const Input = struct {
2 value: u32 = @as(error{}!u32, 0),
3};
4export fn foo() void {
5 var x: Input = Input{};
6 _ = &x;
7}
8
9// error
10//
11//:2:18: error: expected type 'u32', found 'error{}!u32'
12//:2:18: note: cannot convert error union to payload type
13//:2:18: note: consider using 'try', 'catch', or 'if'
test/cases/compile_errors/type_error_union_field_type.zig created+16
......@@ -0,0 +1,16 @@
1fn CreateType() !type {
2 return struct {};
3}
4const MyType = CreateType();
5const TestType = struct {
6 my_type: MyType,
7};
8comptime {
9 _ = @sizeOf(TestType) + 1;
10}
11
12// error
13//
14//:6:14: error: expected type 'type', found 'error{}!type'
15//:6:14: note: cannot convert error union to payload type
16//:6:14: note: consider using 'try', 'catch', or 'if'
test/cases/translate_c/align() attribute.c created+17
......@@ -0,0 +1,17 @@
1__attribute__ ((aligned(128)))
2extern char my_array[16];
3__attribute__ ((aligned(128)))
4void my_fn(void) { }
5void other_fn(void) {
6 char ARR[16] __attribute__ ((aligned (16)));
7}
8
9// translate-c
10// c_frontend=clang
11//
12// pub extern var my_array: [16]u8 align(128);
13// pub export fn my_fn() align(128) void {}
14// pub export fn other_fn() void {
15// var ARR: [16]u8 align(16) = undefined;
16// _ = &ARR;
17// }
test/translate_c.zig-21
......@@ -764,27 +764,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
764764 \\};
765765 });
766766
767 // Test case temporarily disabled:
768 // https://github.com/ziglang/zig/issues/12055
769 if (false) {
770 cases.add("align() attribute",
771 \\__attribute__ ((aligned(128)))
772 \\extern char my_array[16];
773 \\__attribute__ ((aligned(128)))
774 \\void my_fn(void) { }
775 \\void other_fn(void) {
776 \\ char ARR[16] __attribute__ ((aligned (16)));
777 \\}
778 , &[_][]const u8{
779 \\pub extern var my_array: [16]u8 align(128);
780 \\pub export fn my_fn() align(128) void {}
781 \\pub export fn other_fn() void {
782 \\ var ARR: [16]u8 align(16) = undefined;
783 \\ _ = &ARR;
784 \\}
785 });
786 }
787
788767 cases.add("linksection() attribute",
789768 \\// Use the "segment,section" format to make this test pass when
790769 \\// targeting the mach-o binary format