V0010 chained_comparison
Comparison operators do not chain (design §3.1).
An error from the parse phase. sakura explain V0010 prints this explanation offline.
Comparison operators do not chain (design §3.1).
Wrong:
if a < b < c { … }Fixed:
if a < b && b < c { … }Wrong program
compiler/tests/ui/V0010_chained_comparison.sakura, which the compiler's ui suite runs through sakura check:
fn same(a: Int, b: Int, c: Bool) -> Bool { a == b == c }sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:85ff487104b53d58",
"code": "V0010",
"severity": "error",
"phase": "parse",
"message": "comparisons do not chain; combine them with `&&`",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V0010_chained_comparison::same",
"spans": [
{
"uri": "file://$DIR/V0010_chained_comparison.sakura",
"content_hash": "sha256:5c509d943a3a00ba8b2531a8874608d9afbace4826f09400c42170a794175e12",
"start_byte": 84,
"end_byte": 86,
"role": "primary"
}
],
"related_ids": [],
"expected": null,
"actual": null,
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V0010",
"fixes": []
}Fixed program
compiler/tests/ui/V0010_chained_comparison.fixed.sakura, which sakura check accepts with no diagnostics:
fn same(a: Int, b: Int, c: Bool) -> Bool { (a == b) == c }