diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-08-03 02:11:52 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-08-03 02:11:52 -0400 |
| commit | e444e737b786afd0c5aba2ea04c901f89c57813e (patch) | |
| tree | 6740bacbb1cb2189a5a9715af9046f921c8f6319 /test | |
| parent | 24d78177eec4d8fc3aa8ca99dd50788e38f9f8b6 (diff) | |
| download | zig-e444e737b786afd0c5aba2ea04c901f89c57813e.tar.gz zig-e444e737b786afd0c5aba2ea04c901f89c57813e.zip | |
add runtime safety for resuming an awaiting function
Diffstat (limited to 'test')
| -rw-r--r-- | test/runtime_safety.zig | 32 | ||||
| -rw-r--r-- | test/stage1/behavior/coroutines.zig | 2 |
2 files changed, 33 insertions, 1 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index 336dbb8bf0..43cf0856c3 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -1,6 +1,38 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompareOutputContext) void { + cases.addRuntimeSafety("resuming a function which is awaiting a frame", + \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { + \\ @import("std").os.exit(126); + \\} + \\pub fn main() void { + \\ var frame = async first(); + \\ resume frame; + \\} + \\fn first() void { + \\ var frame = async other(); + \\ await frame; + \\} + \\fn other() void { + \\ suspend; + \\} + ); + cases.addRuntimeSafety("resuming a function which is awaiting a call", + \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { + \\ @import("std").os.exit(126); + \\} + \\pub fn main() void { + \\ var frame = async first(); + \\ resume frame; + \\} + \\fn first() void { + \\ other(); + \\} + \\fn other() void { + \\ suspend; + \\} + ); + cases.addRuntimeSafety("invalid resume of async function", \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { \\ @import("std").os.exit(126); diff --git a/test/stage1/behavior/coroutines.zig b/test/stage1/behavior/coroutines.zig index aa77541d19..2b82dce707 100644 --- a/test/stage1/behavior/coroutines.zig +++ b/test/stage1/behavior/coroutines.zig @@ -89,7 +89,7 @@ test "calling an inferred async function" { var other_frame: *@Frame(other) = undefined; fn doTheTest() void { - const p = async first(); + _ = async first(); expect(x == 1); resume other_frame.*; expect(x == 2); |
