Skip to content

Add safety check for await inside nosuspend blocks #8001

Description

@mguaypaq

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions