Commit 3fd2cd4367

Vexu <git@vexu.eu>
2020-03-09 17:38:54
add LemonBoy's test
1 parent 03c1431
Changed files (3)
src/codegen.cpp
@@ -969,7 +969,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
         case PanicMsgIdResumedFnPendingAwait:
             return buf_create_from_str("resumed an async function which can only be awaited");
         case PanicMsgIdBadNoAsyncCall:
-            return buf_create_from_str("async function called with noasync suspended");
+            return buf_create_from_str("async function called in noasync scope suspended");
         case PanicMsgIdResumeNotSuspendedFn:
             return buf_create_from_str("resumed a non-suspended function");
         case PanicMsgIdBadSentinel:
test/stage1/behavior/async_fn.zig
@@ -1531,3 +1531,19 @@ test "noasync await" {
     S.doTheTest();
     expect(S.finished);
 }
+
+test "noasync on function calls" {
+    const S0 = struct {
+        b: i32 = 42,
+    };
+    const S1 = struct {
+        fn c() S0 {
+            return S0{};
+        }
+        fn d() !S0 {
+            return S0{};
+        }
+    };
+    expectEqual(@as(i32, 42), noasync S1.c().b);
+    expectEqual(@as(i32, 42), (try noasync S1.d()).b);
+}
test/compile_errors.zig
@@ -4,11 +4,17 @@ const std = @import("std");
 pub fn addCases(cases: *tests.CompileErrorContext) void {
     cases.addTest("combination of noasync and async",
         \\export fn entry() void {
-        \\    noasync async foo();
+        \\    noasync {
+        \\        const bar = async foo();
+        \\        suspend;
+        \\        resume bar;
+        \\    }
         \\}
         \\fn foo() void {}
     , &[_][]const u8{
-        "tmp.zig:2:13: error: async call in noasync scope",
+        "tmp.zig:3:21: error: async call in noasync scope",
+        "tmp.zig:4:9: error: suspend in noasync scope",
+        "tmp.zig:5:9: error: resume in noasync scope",
     });
 
     cases.addTest("@TypeOf with no arguments",