Commit 60614b2a85

Veikka Tuominen <git@vexu.eu>
2024-03-28 11:58:55
add tests for fixed stage1 bugs
Closes #10357 Closes #11236 Closes #11615 Closes #12055
1 parent 0588595
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
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'
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'
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;
+// }
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