Sisu
E0064

Constructor with more arguments than fields

Error

Built from the repository at commit a8614dc.

A constructor names every field of its class once, in declaration order: Point(x: 1) for a class with the one field x. A variant's constructor does the same for its payload: Shape.Rect(w: 2, h: 3) for a variant with two labeled fields.

Why

Each argument of a constructor sets one field. An argument after the last field has no field to set.

Broken

class Point {
    x: i64
}

fn main() {
    let p = Point(x: 1, y: 2)
    print(p.x)
}

What sisu says

error[E0064]: too many arguments: `Point` has 1 field
 --> E0064.sisu:6:25
  |
6 |     let p = Point(x: 1, y: 2)
  |                         ^^^^

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

Fixed

class Point {
    x: i64
    y: i64
}

fn main() {
    let p = Point(x: 1, y: 2)
    print(p.x + p.y)
}

Related

  • E0056: a constructor without every field.