| author | |
| committer | |
| log | 60614b2a854df0732d0d215a236cf051afd4f832 |
| tree | 25de4b172d6a6215c376f796f7542f7ec40ab562 |
| parent | 0588595128c4534e3a6bc207d446b66032d5720c |
Closes #10357
Closes #11236
Closes #11615
Closes #120555 files changed, 56 insertions(+), 21 deletions(-)
test/behavior/error.zig+10| ... | ... | @@ -930,6 +930,16 @@ test "optional error set return type" { |
| 930 | 930 | try expect(E.A == S.foo(false).?); |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | test "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 | ||
| 933 | 943 | test "returning an error union containing a type with no runtime bits" { |
| 934 | 944 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 935 | 945 | 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 @@ |
| 1 | const Input = struct { | |
| 2 | value: u32 = @as(error{}!u32, 0), | |
| 3 | }; | |
| 4 | export 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 @@ |
| 1 | fn CreateType() !type { | |
| 2 | return struct {}; | |
| 3 | } | |
| 4 | const MyType = CreateType(); | |
| 5 | const TestType = struct { | |
| 6 | my_type: MyType, | |
| 7 | }; | |
| 8 | comptime { | |
| 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))) | |
| 2 | extern char my_array[16]; | |
| 3 | __attribute__ ((aligned(128))) | |
| 4 | void my_fn(void) { } | |
| 5 | void 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 { |
| 764 | 764 | \\}; |
| 765 | 765 | }); |
| 766 | 766 | |
| 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 | ||
| 788 | 767 | cases.add("linksection() attribute", |
| 789 | 768 | \\// Use the "segment,section" format to make this test pass when |
| 790 | 769 | \\// targeting the mach-o binary format |