Skip to content

Calling methods in initializers #78

@vihanb

Description

@vihanb

Initializers should not be able to call methods on self until after the fields have been initialized:

class A {
    let a: Int
    let b: Int

    init() {
        f(); // OK
        self.a = 1
        self.foo() // Error
        self.b = 2
        self.foo() // OK
    }

    func foo() { ... }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions