Skip to content

comptime: declaring a struct in an 'inline for' fails to compile #4148

Closed
@xxxbxxx

Description

@xxxbxxx

hi.

This fails to compile:

export fn func() void {
    inline for ([_]u8{1,2}) |phase| {
        const S = struct {
            val: if (phase == 1) u32 else [2]f32,
        };
        const s = S{.val = if (phase== 1) 1 else [2]f32{1,2} };
    }
}

(with error: 6:57: error: array access of non-array type 'u32')

Looks like the second iteration tries to use the struct from the first iteration or something like this.

If I declare both structs before hand, it works:

export fn func2() void {
    const S1 = struct {
        val: u32,
    };
    const S2 = struct {
        val: [2]f32,
    };
    inline for ([_]u8{1,2}) |phase| {
        const S = if (phase == 1) S1 else S2;
        const s = S{.val = if (phase== 1) 1 else [2]f32{1,2} };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The 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