Skip to content

Reconsider the type of self of an actor to actually be Self #70954

Open
@ktoso

Description

@ktoso

Description

In classes the type of Self is dynamic like this:

class C {
  func f() { self /* self is a C */ }
  func f() -> Self { self /* self is a Self */ }
}

this is because of inheritance.

Inside an actor this causes perhaps surprising errors like this:

dy.swift:3:22: error: cannot convert value of type 'C' to expected argument type 'Self'
    { (x: Self) in }(self)
                     ^
                          as! Self

Actors do not allow inheritance, and therefore we could say that self is always Self.

This would set in stone that actors cannot have inheritance though.

Additional information

Radar: rdar://121091417

Metadata

Metadata

Assignees

No one assigned

    Labels

    Self in classFeature → types: The 'Self' type in classesactorFeature → concurrency: `actor` declarationscompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresdeclarationsFeature: declarationstype checkerArea → compiler: Semantic analysis

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions