Sisu
E0017

Method without self

Error

Built from the repository at commit a8614dc.

A function inside a class is a method, and its first parameter is self.

Why

Sisu has no static methods yet, so every function in a class acts on an object. Write a function that needs no object outside the class.

Broken

class Counter {
    mut n: i64

    fn reset() {
        print(0)
    }
}

fn main() {
    let c = Counter(n: 5)
    c.reset()
    print(c.n)
}

What sisu says

error[E0017]: a method needs `self` as its first parameter
 --> E0017.sisu:4:8
  |
4 |     fn reset() {
  |        ^^^^^
  |
  = help: static methods are not supported yet

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

Fixed

class Counter {
    mut n: i64

    fn reset(self) {
        self.n = 0
    }
}

fn main() {
    let c = Counter(n: 5)
    c.reset()
    print(c.n)
}