Sisu
E0087

Constant that uses itself or a constant below it

Error

Built from the repository at commit a8614dc.

A constant can use only the constants declared above it. One that names a constant below it, or names itself, is an error.

Why

The compiler computes constants from top to bottom, so each value is known before the constants below it use it. This also rules out a constant that depends on itself, whose value would have no start. Functions and classes may still appear in any order. Move the constant that is used above the one that uses it.

Broken

const PERIMETER = SIDE * 4
const SIDE = 10

fn main() {
    print(PERIMETER)
}

What sisu says

error[E0087]: `SIDE` is declared below `PERIMETER`
 --> E0087.sisu:1:19
  |
1 | const PERIMETER = SIDE * 4
  |                   ^^^^
2 | const SIDE = 10
  |       ---- declared here
  |
  = help: move `SIDE` above `PERIMETER`

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0087

Fixed

const SIDE = 10
const PERIMETER = SIDE * 4

fn main() {
    print(PERIMETER)
}

Related

  • E0086: constant value not known at compile time.