As discussed in #7972 (specifically, this comment by @SpexGuy), the zig compiler currently (version 0.7.1) doesn't put in a safety check when, inside a nosuspend block, we await an async function which has not yet completed. Instead, a garbage value is silently used as the function's return value.
The compiler should put in a safety check to check whether the awaited function has completed.
pub fn main() void {
var f = async not_done_yet();
// This is undefined behavior and should be safety-checked.
var i = nosuspend await f;
@import("std").debug.print("garbage: {}\n", .{i});
}
fn not_done_yet() u8 {
suspend;
suspend;
return 2;
}
As discussed in #7972 (specifically, this comment by @SpexGuy), the zig compiler currently (version 0.7.1) doesn't put in a safety check when, inside a
nosuspendblock, weawaitan async function which has not yet completed. Instead, a garbage value is silently used as the function's return value.The compiler should put in a safety check to check whether the
awaited function has completed.