From 60614b2a854df0732d0d215a236cf051afd4f832 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Thu, 28 Mar 2024 12:58:55 +0200 Subject: [PATCH] add tests for fixed stage1 bugs Closes #10357 Closes #11236 Closes #11615 Closes #12055 --- test/behavior/error.zig | 10 +++++++++ .../error_union_field_default_init.zig | 13 ++++++++++++ .../type_error_union_field_type.zig | 16 ++++++++++++++ test/cases/translate_c/align() attribute.c | 17 +++++++++++++++ test/translate_c.zig | 21 ------------------- 5 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 test/cases/compile_errors/error_union_field_default_init.zig create mode 100644 test/cases/compile_errors/type_error_union_field_type.zig create mode 100644 test/cases/translate_c/align() attribute.c diff --git a/test/behavior/error.zig b/test/behavior/error.zig index 952d010a14..8380c89619 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -930,6 +930,16 @@ test "optional error set return type" { try expect(E.A == S.foo(false).?); } +test "optional error set function parameter" { + const S = struct { + fn doTheTest(a: ?anyerror) !void { + try std.testing.expect(a.? == error.OutOfMemory); + } + }; + try S.doTheTest(error.OutOfMemory); + try comptime S.doTheTest(error.OutOfMemory); +} + test "returning an error union containing a type with no runtime bits" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO diff --git a/test/cases/compile_errors/error_union_field_default_init.zig b/test/cases/compile_errors/error_union_field_default_init.zig new file mode 100644 index 0000000000..c3d9a62389 --- /dev/null +++ b/test/cases/compile_errors/error_union_field_default_init.zig @@ -0,0 +1,13 @@ +const Input = struct { + value: u32 = @as(error{}!u32, 0), +}; +export fn foo() void { + var x: Input = Input{}; + _ = &x; +} + +// error +// +//:2:18: error: expected type 'u32', found 'error{}!u32' +//:2:18: note: cannot convert error union to payload type +//:2:18: note: consider using 'try', 'catch', or 'if' diff --git a/test/cases/compile_errors/type_error_union_field_type.zig b/test/cases/compile_errors/type_error_union_field_type.zig new file mode 100644 index 0000000000..74aa93bc6a --- /dev/null +++ b/test/cases/compile_errors/type_error_union_field_type.zig @@ -0,0 +1,16 @@ +fn CreateType() !type { + return struct {}; +} +const MyType = CreateType(); +const TestType = struct { + my_type: MyType, +}; +comptime { + _ = @sizeOf(TestType) + 1; +} + +// error +// +//:6:14: error: expected type 'type', found 'error{}!type' +//:6:14: note: cannot convert error union to payload type +//:6:14: note: consider using 'try', 'catch', or 'if' diff --git a/test/cases/translate_c/align() attribute.c b/test/cases/translate_c/align() attribute.c new file mode 100644 index 0000000000..600e8251fb --- /dev/null +++ b/test/cases/translate_c/align() attribute.c @@ -0,0 +1,17 @@ +__attribute__ ((aligned(128))) +extern char my_array[16]; +__attribute__ ((aligned(128))) +void my_fn(void) { } +void other_fn(void) { + char ARR[16] __attribute__ ((aligned (16))); +} + +// translate-c +// c_frontend=clang +// +// pub extern var my_array: [16]u8 align(128); +// pub export fn my_fn() align(128) void {} +// pub export fn other_fn() void { +// var ARR: [16]u8 align(16) = undefined; +// _ = &ARR; +// } diff --git a/test/translate_c.zig b/test/translate_c.zig index a390810830..3b201e2c11 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -764,27 +764,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; }); - // Test case temporarily disabled: - // https://github.com/ziglang/zig/issues/12055 - if (false) { - cases.add("align() attribute", - \\__attribute__ ((aligned(128))) - \\extern char my_array[16]; - \\__attribute__ ((aligned(128))) - \\void my_fn(void) { } - \\void other_fn(void) { - \\ char ARR[16] __attribute__ ((aligned (16))); - \\} - , &[_][]const u8{ - \\pub extern var my_array: [16]u8 align(128); - \\pub export fn my_fn() align(128) void {} - \\pub export fn other_fn() void { - \\ var ARR: [16]u8 align(16) = undefined; - \\ _ = &ARR; - \\} - }); - } - cases.add("linksection() attribute", \\// Use the "segment,section" format to make this test pass when \\// targeting the mach-o binary format