diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-22 14:36:14 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-07-22 14:36:14 -0400 |
| commit | fcadeb50c04199fce2d9675ba2976680c71c67ff (patch) | |
| tree | 6d4bba1ab17adc6f6b42539c2dbeadf166327e37 /test | |
| parent | 650e07ebd96d6c476cadc1f7c19856e950ceef9c (diff) | |
| download | zig-fcadeb50c04199fce2d9675ba2976680c71c67ff.tar.gz zig-fcadeb50c04199fce2d9675ba2976680c71c67ff.zip | |
fix multiple coroutines existing clobbering each other
Diffstat (limited to 'test')
| -rw-r--r-- | test/runtime_safety.zig | 14 | ||||
| -rw-r--r-- | test/stage1/behavior/coroutines.zig | 18 |
2 files changed, 32 insertions, 0 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index aee607e10f..336dbb8bf0 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -1,6 +1,20 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompareOutputContext) void { + cases.addRuntimeSafety("invalid resume of async function", + \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { + \\ @import("std").os.exit(126); + \\} + \\pub fn main() void { + \\ var p = async suspendOnce(); + \\ resume p; //ok + \\ resume p; //bad + \\} + \\fn suspendOnce() void { + \\ suspend; + \\} + ); + cases.addRuntimeSafety(".? operator on null pointer", \\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 3a54657020..4ecd4efd13 100644 --- a/test/stage1/behavior/coroutines.zig +++ b/test/stage1/behavior/coroutines.zig @@ -29,6 +29,24 @@ fn simpleAsyncFnWithArg(delta: i32) void { suspend; global_y += delta; } + +test "suspend at end of function" { + const S = struct { + var x: i32 = 1; + + fn doTheTest() void { + expect(x == 1); + const p = async suspendAtEnd(); + expect(x == 2); + } + + fn suspendAtEnd() void { + x += 1; + suspend; + } + }; + S.doTheTest(); +} //test "coroutine suspend, resume" { // seq('a'); // const p = try async<allocator> testAsyncSeq(); |
