# V0010 chained_comparison

URL: /docs/errors/V0010
Markdown: /docs/errors/V0010.md

> 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:

```sakura
if a < b < c { … }
```

Fixed:

```sakura
if a < b && b < c { … }
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V0010_chained_comparison.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V0010_chained_comparison.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
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):

```json
{
  "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 [#fixed-program]

[`compiler/tests/ui/V0010_chained_comparison.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V0010_chained_comparison.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
fn same(a: Int, b: Int, c: Bool) -> Bool { (a == b) == c }
```
