Skip to content
Playground(another site)

bynk.parse.non_associative

Error A non-associative operator was chained (e.g. a == b == c).

Comparisons (<, <=, >, >=) and equality tests (==, !=) do not chain, so a < b < c is refused rather than given a reading you may not have meant. Split a chain of comparisons with &&; to test the result of an equality, parenthesise it: (a == b) == c.

Example

fn ordered(a: Int, b: Int, c: Int) -> Bool {
a < b < c // ✗ comparisons do not chain
}
fn ordered(a: Int, b: Int, c: Int) -> Bool {
a < b && b < c // ✓ one comparison on each side of `&&`
}

In the Book

See also

  • The grammar rule it governs: binary_expr.
  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.non_associative shows the same from the installed toolchain, without a network.