Sisu
E0057

Method read as a field

ErrorSafe fix

Built from the repository at commit a8614dc.

A method runs when it is called, with () and its arguments: s.area(). Without the call, s.area reads a field, and the class has no field of that name. The same holds for the array method len().

Why

Sisu has no method values: a method name alone is not a value that a program can store or pass. Reading one is almost always a call with its () left out.

Broken

class Square {
    side: i64

    fn area(self) -> i64 {
        self.side * self.side
    }
}

fn main() {
    let s = Square(side: 2)
    print(s.area)
}

What sisu says

error[E0057]: `area` is a method of `Square`, not a field
  --> E0057.sisu:11:13
   |
11 |     print(s.area)
   |             ^^^^
   |
help: call it: `area()`
   |
11 |     print(s.area())
   |                 ++

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

Fixed

class Square {
    side: i64

    fn area(self) -> i64 {
        self.side * self.side
    }
}

fn main() {
    let s = Square(side: 2)
    print(s.area())
}

Related

  • E0058: a field called as a method.