aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2019-08-30 13:02:28 +0200
committerRobin Voetter <robin@voetter.nl>2019-08-30 13:02:28 +0200
commitca2aa4880f468f12bcbe3d6cd315729dd361eff2 (patch)
tree92bdee1022a3497b2f048e450b23d4e585a649f8 /test
parent4b8325f3815c7fa774bb06ef5d190f039723222b (diff)
parent10541c8fc88875cb51df0a5fdeda20847133e676 (diff)
downloadzig-ca2aa4880f468f12bcbe3d6cd315729dd361eff2.tar.gz
zig-ca2aa4880f468f12bcbe3d6cd315729dd361eff2.zip
Merge remote-tracking branch 'upstream/master' into arm-support-improvement
Diffstat (limited to 'test')
-rw-r--r--test/compile_errors.zig8
-rw-r--r--test/stage1/behavior/array.zig6
-rw-r--r--test/stage1/behavior/async_fn.zig10
-rw-r--r--test/stage1/behavior/error.zig20
-rw-r--r--test/stage1/behavior/sizeof_and_typeof.zig15
5 files changed, 55 insertions, 4 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 812b236716..91916e6f38 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -273,7 +273,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
,
"tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
- "tmp.zig:3:18: note: await is a suspend point",
+ "tmp.zig:3:18: note: await here is a suspend point",
);
cases.add(
@@ -507,11 +507,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@sizeOf bad type",
- \\export fn entry() void {
- \\ _ = @sizeOf(@typeOf(null));
+ \\export fn entry() usize {
+ \\ return @sizeOf(@typeOf(null));
\\}
,
- "tmp.zig:2:17: error: no size available for type '(null)'",
+ "tmp.zig:2:20: error: no size available for type '(null)'",
);
cases.add(
diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig
index 9349af573c..462977066e 100644
--- a/test/stage1/behavior/array.zig
+++ b/test/stage1/behavior/array.zig
@@ -292,3 +292,9 @@ test "read/write through global variable array of struct fields initialized via
};
S.doTheTest();
}
+
+test "implicit cast zero sized array ptr to slice" {
+ var b = "";
+ const c: []const u8 = &b;
+ expect(c.len == 0);
+}
diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig
index ccfc4d1ea6..dfed1c4ab7 100644
--- a/test/stage1/behavior/async_fn.zig
+++ b/test/stage1/behavior/async_fn.zig
@@ -844,3 +844,13 @@ test "cast fn to async fn when it is inferred to be async" {
resume S.frame;
expect(S.ok);
}
+
+test "await does not force async if callee is blocking" {
+ const S = struct {
+ fn simple() i32 {
+ return 1234;
+ }
+ };
+ var x = async S.simple();
+ expect(await x == 1234);
+}
diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig
index 264f140c9d..fefd95a850 100644
--- a/test/stage1/behavior/error.zig
+++ b/test/stage1/behavior/error.zig
@@ -375,3 +375,23 @@ test "implicit cast to optional to error union to return result loc" {
S.entry();
//comptime S.entry(); TODO
}
+
+test "function pointer with return type that is error union with payload which is pointer of parent struct" {
+ const S = struct {
+ const Foo = struct {
+ fun: fn (a: i32) (anyerror!*Foo),
+ };
+
+ const Err = error{UnspecifiedErr};
+
+ fn bar(a: i32) anyerror!*Foo {
+ return Err.UnspecifiedErr;
+ }
+
+ fn doTheTest() void {
+ var x = Foo{ .fun = bar };
+ expectError(error.UnspecifiedErr, x.fun(1));
+ }
+ };
+ S.doTheTest();
+}
diff --git a/test/stage1/behavior/sizeof_and_typeof.zig b/test/stage1/behavior/sizeof_and_typeof.zig
index cfad311e06..da79c3a270 100644
--- a/test/stage1/behavior/sizeof_and_typeof.zig
+++ b/test/stage1/behavior/sizeof_and_typeof.zig
@@ -74,3 +74,18 @@ test "@sizeOf on compile-time types" {
expect(@sizeOf(@typeOf(.hi)) == 0);
expect(@sizeOf(@typeOf(type)) == 0);
}
+
+test "@sizeOf(T) == 0 doesn't force resolving struct size" {
+ const S = struct {
+ const Foo = struct {
+ y: if (@sizeOf(Foo) == 0) u64 else u32,
+ };
+ const Bar = struct {
+ x: i32,
+ y: if (0 == @sizeOf(Bar)) u64 else u32,
+ };
+ };
+
+ expect(@sizeOf(S.Foo) == 4);
+ expect(@sizeOf(S.Bar) == 8);
+}