zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3fd2cd43678d52ca2f737d991edaddfd8b73c2a4 (tree)
parent 03c1431f9c0b651f3f1853f11112edc07555883d
Author: Vexu <git@vexu.eu>
Date:   Mon,  9 Mar 2020 18:38:54 +0200

add LemonBoy's test

Diffstat:
Msrc/codegen.cpp | 2+-
Mtest/compile_errors.zig | 10++++++++--
Mtest/stage1/behavior/async_fn.zig | 16++++++++++++++++
3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/codegen.cpp b/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: diff --git a/test/compile_errors.zig 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", diff --git a/test/stage1/behavior/async_fn.zig b/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); +}