Lyricdev
GitHub

LYR-PAR0059

comparisons or equalities chained

error ยท spec 08-expressions

A comparison (<, <=, >, >=, in, not in) is followed by another one, or == or != by another, as in a < b < c or a == b == c.

Explanation

These operators have no associativity. a < b < c would compare the bool of a < b with c, which is never what is meant; a == b == c would compare a bool with c and may even type.

Compare twice and join with &&, or group one comparison in parentheses.

Wrong

fn main(): void {
    let a = 1;
    let b = 2;
    let c = 3;
    let t = a < b < c;
}
fn main(): void {
    let a = 1;
    let b = 2;
    let c = 3;
    let t = a < b && b < c;
    let _ = t;
}