add LemonBoy's test

master
Vexu 2020-03-09 18:38:54 +02:00
parent 03c1431f9c
commit 3fd2cd4367
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 25 additions and 3 deletions

View File

@ -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:

View File

@ -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",

View File

@ -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);
}