Files
swift-mirror/test/Distributed/distributed_actor_initialization.swift
Kavon Farvardin 41134ea8a0 Remove the need for convenience on actor inits to delegate.
This is possible because actors do not support inheritance. There
is one specific exception to that rule, which is that an actor
can inherit from `NSObject` just to support ObjC interop.

This means an actor is effectively a final class.

resolves rdar://87568153
2022-06-27 16:01:08 -07:00

72 lines
1.7 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -I %t 2>&1 %s
// REQUIRES: concurrency
// REQUIRES: distributed
import Distributed
import FakeDistributedActorSystems
@available(SwiftStdlib 5.5, *)
typealias DefaultDistributedActorSystem = FakeActorSystem
// ==== ----------------------------------------------------------------------------------------------------------------
distributed actor OK0 { }
distributed actor OK1 {
var x: Int = 1
// ok, since all fields are initialized, the constructor can be synthesized
}
distributed actor OK2 {
var x: Int
init(x: Int, system: FakeActorSystem) { // ok
self.x = x
}
}
// NOTE: keep in mind this is only through typechecking, so no explicit
// actorSystem is being assigned here.
distributed actor OK3 {
init() {}
}
distributed actor OK4 {
init(x: String) {
}
}
distributed actor OK5 {
var x: Int = 1
init(system: FakeActorSystem, too many: FakeActorSystem) {
}
}
distributed actor OK6 {
var x: Int
init(y: Int, system: FakeActorSystem) {
self.x = y
}
}
distributed actor OKMulti {
convenience init(y: Int, system: FakeActorSystem) { // expected-warning{{initializers in actors are not marked with 'convenience'; this is an error in Swift 6}}{{3-15=}}
self.init(actorSystem: system)
}
}
distributed actor OKMultiDefaultValues {
init(y: Int, system: FakeActorSystem, x: Int = 1234) { // ok
self.init(actorSystem: system)
}
}