Skip to content

compile-time use of undefined value detection #597

@andrewrk

Description

@andrewrk
extern fn bar();
export fn entry() {
    var a: i32 = undefined;
    if (a > 10) {
        bar();
    }
}

Zig should be able to detect that we will with 100% certainty branch on an undefined value.

Related:

export fn entry() {
    unreachable;
}

Should be an error, because it's 100% certain at compile-time that we will reach unreachable code.

Not to be confused with #211 which is adding extra code and data in safety-enabled builds to detect use of undefined value at runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions