Skip to content

Inline loop over functions where one returns empty error set gives compiler error #1957

Closed
@Hejsil

Description

@Hejsil

I would expect this to work, but it doesn't.

const T1 = struct {
    pub fn v() error{}!usize {
        return usize(0);
    }
};

const T2 = struct {
    pub fn v() error{Error}!usize {
        return usize(1);
    }
};

test "" {
    const ts = []type{
        T1,
        T2,
    };
    inline for (ts) |T|
        _ = try T.v();
}
test.zig:19:13: error: control flow attempts to use compile-time variable at runtime
        _ = try T.v();
            ^
test.zig:18:12: note: compile-time variable assigned here
    inline for (ts) |T|

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions