Skip to content

Invalid codegen: if-@as-if #8952

@ghost

Description

const std = @import("std");

pub fn main() void {
    var fast = true;
    var very_fast = false;

    const num_frames = if (fast)
        @as(u32, if (very_fast) 16 else 4)
        //if (very_fast) @as(u32, 16) else @as(u32, 4)
    else
        1;

    std.debug.warn("{}\n", .{num_frames});
}

This prints 16. The commented out line works normally (prints 4).

Broken on both Zig 0.7.1 and 0.8.0-dev.2711+11ae6c42c

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.stage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions