Skip to content

Commit ee43ea8

Browse files
committed
[Distributed] fix AnyActorIdentity equality impl
1 parent e1bfc46 commit ee43ea8

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable, CustomString
138138
.hash(into: &hasher)
139139
}
140140
_equalTo = { other in
141-
guard let rhs = other as? ID else {
141+
guard let otherAnyIdentity = other as? AnyActorIdentity else {
142+
return false
143+
}
144+
guard let rhs = otherAnyIdentity.underlying as? ID else {
142145
return false
143146
}
144147
return identity == rhs
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-distributed -parse-as-library)
2+
3+
// REQUIRES: executable_test
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
7+
// rdar://76038845
8+
// UNSUPPORTED: use_os_stdlib
9+
// UNSUPPORTED: back_deployment_runtime
10+
11+
import StdlibUnittest
12+
import _Distributed
13+
14+
@available(SwiftStdlib 5.5, *)
15+
struct ActorAddress: ActorIdentity, CustomStringConvertible {
16+
let id: String
17+
var description: Swift.String {
18+
"ActorAddress(id: \(id))"
19+
}
20+
}
21+
22+
@main struct Main {
23+
static func main() async {
24+
if #available(SwiftStdlib 5.5, *) {
25+
26+
let ActorIdentityTests = TestSuite("ActorIdentity")
27+
28+
ActorIdentityTests.test("equality") {
29+
let a = ActorAddress(id: "a")
30+
let b = ActorAddress(id: "b")
31+
32+
let anyA = AnyActorIdentity(a)
33+
let anyB = AnyActorIdentity(b)
34+
35+
expectEqual(a, a)
36+
expectEqual(anyA, anyA)
37+
38+
expectNotEqual(a, b)
39+
expectNotEqual(anyA, anyB)
40+
}
41+
42+
ActorIdentityTests.test("hash") {
43+
let a = ActorAddress(id: "a")
44+
let b = ActorAddress(id: "b")
45+
46+
let anyA = AnyActorIdentity(a)
47+
let anyB = AnyActorIdentity(b)
48+
49+
expectEqual(a.hashValue, a.hashValue)
50+
expectEqual(anyA.hashValue, anyA.hashValue)
51+
52+
expectNotEqual(a.hashValue, b.hashValue)
53+
expectNotEqual(anyA.hashValue, anyB.hashValue)
54+
}
55+
}
56+
57+
await runAllTestsAsync()
58+
}
59+
}

0 commit comments

Comments
 (0)