Sisu
E0107

**

ErrorUnsafe fix

Built from the repository at commit a8614dc.

Sisu has no ** operator. A power is the method call x.pow(y), on an f64. The error points at the **. The program does not build, and the parser reports it once, even for x **= 2.

The fix is unsafe. It rewrites l ** r to l.pow(r) when both sides are plain operands: a name, a float literal, a call, a field, a method call, an index or anything in parentheses, and on the right any literal. It offers nothing for 2 ** 10, because 2.pow(10) does not check: an integer has no pow. It offers nothing for x **= 2, or for x ** 2 ** 3, which Python reads from the right.

Why

** looks like a power, and the parser can read it, but the type of the left side decides what a power means, and an f64 is the only number that has one. A method says so on the value it works on. The fix is unsafe because the parser cannot see the left side's type.

Broken

fn main() {
    let x = 3.0
    print(x ** 2)
}

What sisu says

error[E0107]: Sisu has no `**`
 --> E0107.sisu:3:13
  |
3 |     print(x ** 2)
  |             ^^
  |
  = help: use `x.pow(y)`
help: try a `pow` call, which needs an `f64` on the left
  |
3 -     print(x ** 2)
3 +     print(x.pow(2))
  |

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

Fixed

fn main() {
    let x = 3.0
    print(x.pow(2))
}

Related

  • E0106: math written another way, such as math.sqrt(x).