Files
swift-mirror/test/decl/protocol/special/DistributedActor.swift
Holly Borla 1011e4ddb0 [Concurrency] Only deprecate AnyActor, and update more tests.
Obsoleting `AnyActor` in Swift 6 blocks the Concurrency library itself
from migrating to Swift 6, because `Actor` and `DistributedActor` have to
preserve their refinement of `AnyActor` to avoid breaking code currently
using the marker protocol. There's no way to move protocol refinement into
an extension so that the use-site declaration can be obsoleted, so we're
stuck with just the deprecation of `AnyActor`.
2024-05-24 12:58:02 -07:00

90 lines
2.9 KiB
Swift

// RUN: %target-typecheck-verify-swift -disable-availability-checking -verify-ignore-unknown
// REQUIRES: concurrency
// REQUIRES: distributed
import Distributed
/// Use the existential wrapper as the default actor system.
typealias DefaultDistributedActorSystem = LocalTestingDistributedActorSystem
distributed actor D0 {
typealias ActorSystem = LocalTestingDistributedActorSystem
var x: Int = 17
}
distributed actor D1 {
var x: Int = 17
}
class X: Identifiable {
// should work as expected, synthesis not triggering
func test() {
let _: ObjectIdentifier = self.id
}
}
protocol DAP: DistributedActor {
// should work as expected, synthesis not triggering
func test()
}
extension DAP where ActorSystem.ActorID == String {
func test() {
_ = self.id == ""
}
}
distributed actor D2 {
let actorSystem: String
// expected-error@-1{{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
}
distributed actor D3 {
var id: Int { 0 }
// expected-error@-1{{property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
}
struct OtherActorIdentity: Sendable, Hashable, Codable {}
distributed actor D4 {
let actorSystem: String
// expected-error@-1{{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
let id: OtherActorIdentity
// expected-error@-1{{property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
}
protocol P1: DistributedActor {
distributed func dist() -> String
// expected-note@-1{{'dist()' declared here}}
}
distributed actor D5: P1 {
func dist() -> String { "" }
// expected-error@-1{{distributed actor-isolated instance method 'dist()' cannot be used to satisfy actor-isolated protocol requirement}}
// expected-note@-2{{add 'distributed' to 'dist()' to make this instance method satisfy the protocol requirement}}{{3-3=distributed }}
}
// ==== Tests ------------------------------------------------------------------
// Make sure the conformances have been added implicitly.
func acceptDistributedActor<Act: DistributedActor>(_: Act.Type) { }
func acceptAnyActor<Act: AnyActor>(_: Act.Type) { } // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
func testConformance() {
acceptDistributedActor(D1.self)
acceptAnyActor(D1.self)
}
// https://github.com/apple/swift/issues/69244
protocol P {
func foo() -> Void
// expected-note@-1{{mark the protocol requirement 'foo()' 'async throws' to allow actor-isolated conformances}}{{13-13= async throws}}
}
distributed actor A: P {
typealias ActorSystem = LocalTestingDistributedActorSystem
distributed func foo() { }
// expected-error@-1{{actor-isolated distributed instance method 'foo()' cannot be used to satisfy nonisolated protocol requirement}}
}
// ---