Zig unable to resolve comptime value in an if expression for two arguments

This compiles

if (replacement.items.len == 0) {
    try replacement.insertSlice(allocator, 3, "foo");
} else if (containsString(&keywords, replacement.items)) {
    try replacement.insertSlice(allocator, 3, "foo");
}

but this doesn’t

if (replacement.items.len == 0 || containsString(&keywords, replacement.items)) {
    try replacement.insertSlice(allocator, 3, "foo");
}
src/main.zig:245:76: error: unable to resolve comptime value
    if (replacement.items.len == 0 || containsString(&keywords, replacement.items)) {
                                                                ~~~~~~~~~~~^~~~~~
src/main.zig:245:53: note: types must be comptime-known
    if (replacement.items.len == 0 || containsString(&keywords, replacement.items)) {
                                      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can smb please explain please?

you need to use the or operator, not the || operator. The || operator is a union operation over error sets, or is for the boolean “or” operation that you want to perform in your sample :smiley:

6 Likes

Omg, sorry, I completly forgot

1 Like

There is a checkbox like button on each comment you can use to mark that comment as the solution.