[Distributed] Add more tests for implicit Codable on distributed actors

This commit is contained in:
Konrad `ktoso` Malawski
2024-04-16 21:29:28 +09:00
parent 70757ffe5e
commit efd8cbf978
3 changed files with 270 additions and 0 deletions

View File

@@ -17,3 +17,48 @@ func take<A: Codable>(actor: A) {}
func test(actorSystem: FakeActorSystem) {
take(actor: DA(actorSystem: actorSystem)) // ok
}
func takeCodable<A: Codable>(actor: A) {}
func test_DA(actorSystem: FakeActorSystem) {
takeCodable(actor: DA(actorSystem: actorSystem)) // ok
}
// ==== Generic actors
distributed actor DAG<ActorSystem>
where ActorSystem: DistributedActorSystem<any Codable> {
}
func test_DAG(actorSystem: FakeActorSystem) {
takeCodable(actor: DAG<FakeActorSystem>(actorSystem: actorSystem)) // ok
}
distributed actor DAG_ID<ActorSystem>
where ActorSystem: DistributedActorSystem<any Codable>,
ID: Codable { // expected-error{{cannot find type 'ID' in scope}}
}
func test_DAG_ID(actorSystem: FakeActorSystem) {
takeCodable(actor: DAG_ID<FakeActorSystem>(actorSystem: actorSystem)) // ok
}
distributed actor DAG_ActorSystem_ActorID<ActorSystem>
where ActorSystem: DistributedActorSystem<any Codable>,
ActorSystem.ActorID: Codable {
}
func test_DAG_ActorSystem_ActorID(actorSystem: FakeActorSystem) {
takeCodable(actor: DAG_ActorSystem_ActorID<FakeActorSystem>(actorSystem: actorSystem)) // ok
}
// ==== Not codable cases
protocol SerializableButNotCodable {}
distributed actor DAG_ActorSystem_ActorID_Custom<ActorSystem>
where ActorSystem: DistributedActorSystem<any SerializableButNotCodable> {
// expected-note@-2{{requirement specified as 'ActorSystem.SerializationRequirement' == 'any SerializableButNotCodable'}}
}
func test_DAG_ActorSystem_ActorID_Custom(actorSystem: FakeActorSystem) {
takeCodable(actor: DAG_ActorSystem_ActorID_Custom<FakeActorSystem>(actorSystem: actorSystem))
// expected-error@-1{{'DAG_ActorSystem_ActorID_Custom' requires the types 'any FakeActorSystem.SerializationRequirement' (aka 'any Decodable & Encodable') and 'any SerializableButNotCodable' be equivalent}}
}