| author | |
| committer | |
| log | 3fd2cd43678d52ca2f737d991edaddfd8b73c2a4 |
| tree | 1a69d7283d69664631b6d07a87257355bb71e2eb |
| parent | 03c1431f9c0b651f3f1853f11112edc07555883d |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 25 insertions(+), 3 deletions(-)
src/codegen.cpp+1-1| ... | ... | @@ -969,7 +969,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) { |
| 969 | 969 | case PanicMsgIdResumedFnPendingAwait: |
| 970 | 970 | return buf_create_from_str("resumed an async function which can only be awaited"); |
| 971 | 971 | case PanicMsgIdBadNoAsyncCall: |
| 972 | return buf_create_from_str("async function called with noasync suspended"); | |
| 972 | return buf_create_from_str("async function called in noasync scope suspended"); | |
| 973 | 973 | case PanicMsgIdResumeNotSuspendedFn: |
| 974 | 974 | return buf_create_from_str("resumed a non-suspended function"); |
| 975 | 975 | case PanicMsgIdBadSentinel: |
test/compile_errors.zig+8-2| ... | ... | @@ -4,11 +4,17 @@ const std = @import("std"); |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | 5 | cases.addTest("combination of noasync and async", |
| 6 | 6 | \\export fn entry() void { |
| 7 | \\ noasync async foo(); | |
| 7 | \\ noasync { | |
| 8 | \\ const bar = async foo(); | |
| 9 | \\ suspend; | |
| 10 | \\ resume bar; | |
| 11 | \\ } | |
| 8 | 12 | \\} |
| 9 | 13 | \\fn foo() void {} |
| 10 | 14 | , &[_][]const u8{ |
| 11 | "tmp.zig:2:13: error: async call in noasync scope", | |
| 15 | "tmp.zig:3:21: error: async call in noasync scope", | |
| 16 | "tmp.zig:4:9: error: suspend in noasync scope", | |
| 17 | "tmp.zig:5:9: error: resume in noasync scope", | |
| 12 | 18 | }); |
| 13 | 19 | |
| 14 | 20 | cases.addTest("@TypeOf with no arguments", |
test/stage1/behavior/async_fn.zig+16| ... | ... | @@ -1531,3 +1531,19 @@ test "noasync await" { |
| 1531 | 1531 | S.doTheTest(); |
| 1532 | 1532 | expect(S.finished); |
| 1533 | 1533 | } |
| 1534 | ||
| 1535 | test "noasync on function calls" { | |
| 1536 | const S0 = struct { | |
| 1537 | b: i32 = 42, | |
| 1538 | }; | |
| 1539 | const S1 = struct { | |
| 1540 | fn c() S0 { | |
| 1541 | return S0{}; | |
| 1542 | } | |
| 1543 | fn d() !S0 { | |
| 1544 | return S0{}; | |
| 1545 | } | |
| 1546 | }; | |
| 1547 | expectEqual(@as(i32, 42), noasync S1.c().b); | |
| 1548 | expectEqual(@as(i32, 42), (try noasync S1.d()).b); | |
| 1549 | } |