authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-03-09 18:38:54+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-03-09 18:43:09+02:00
log3fd2cd43678d52ca2f737d991edaddfd8b73c2a4
tree1a69d7283d69664631b6d07a87257355bb71e2eb
parent03c1431f9c0b651f3f1853f11112edc07555883d
signaturelock-open Commit is signed but in an unrecognized format.

add LemonBoy's test


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,7 +969,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
969 case PanicMsgIdResumedFnPendingAwait:969 case PanicMsgIdResumedFnPendingAwait:
970 return buf_create_from_str("resumed an async function which can only be awaited");970 return buf_create_from_str("resumed an async function which can only be awaited");
971 case PanicMsgIdBadNoAsyncCall: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 case PanicMsgIdResumeNotSuspendedFn:973 case PanicMsgIdResumeNotSuspendedFn:
974 return buf_create_from_str("resumed a non-suspended function");974 return buf_create_from_str("resumed a non-suspended function");
975 case PanicMsgIdBadSentinel:975 case PanicMsgIdBadSentinel:
test/compile_errors.zig+8-2
...@@ -4,11 +4,17 @@ const std = @import("std");...@@ -4,11 +4,17 @@ const std = @import("std");
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.addTest("combination of noasync and async",5 cases.addTest("combination of noasync and async",
6 \\export fn entry() void {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 \\fn foo() void {}13 \\fn foo() void {}
10 , &[_][]const u8{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 });
1319
14 cases.addTest("@TypeOf with no arguments",20 cases.addTest("@TypeOf with no arguments",
test/stage1/behavior/async_fn.zig+16
...@@ -1531,3 +1531,19 @@ test "noasync await" {...@@ -1531,3 +1531,19 @@ test "noasync await" {
1531 S.doTheTest();1531 S.doTheTest();
1532 expect(S.finished);1532 expect(S.finished);
1533}1533}
1534
1535test "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}