Skip to content

Commit

Permalink
add tests for fixed stage1 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Mar 28, 2024
1 parent de6b36b commit 8fc01a4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
10 changes: 10 additions & 0 deletions test/behavior/error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/cases/compile_errors/error_union_field_default_init.zig
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions test/cases/compile_errors/type_error_union_field_type.zig
Original file line number Diff line number Diff line change
@@ -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'
17 changes: 17 additions & 0 deletions test/cases/translate_c/align() attribute.c
Original file line number Diff line number Diff line change
@@ -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;
//}
21 changes: 0 additions & 21 deletions test/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8fc01a4

Please sign in to comment.