#compile error triggered when it shouldn't be

1 messages · Page 1 of 1 (latest)

tepid kayak
#

So I have this function:

    pub fn find(comptime name: [:0]const u8, comptime uniforms: []const UniformInfo) UniformInfo {
        for (uniforms) |un| {
            if (std.mem.eql(u8, un.name, name)) {
                return un;
            }
        }
        @compileError("Unknown uniform field name");
    }

And for some reason the compile error gets triggered, even though the function returns correctly and when I comment the @error out it works perfectly fine. Why is this?

shrewd karma
#

Call eql at comptime: if (comptime std.mem.eql(u8, un.name, name)) {

#

Functions are not eagerly evaluated at compile time, even if their arguments are known at compile time