From 3fd2cd43678d52ca2f737d991edaddfd8b73c2a4 Mon Sep 17 00:00:00 2001 From: Vexu Date: Mon, 9 Mar 2020 18:38:54 +0200 Subject: [PATCH] add LemonBoy's test --- src/codegen.cpp | 2 +- test/compile_errors.zig | 10 ++++++++-- test/stage1/behavior/async_fn.zig | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 52ac2e7936..a67b8dc00b 100644 --- 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 index 7021f81554..4434920224 100644 --- 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 index 6583adec66..6b99187563 100644 --- 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); +}