@@ -20,20 +20,36 @@ distributed actor D2 {
20
20
}
21
21
22
22
distributed actor D3 {
23
+ // expected-error@-1{{protocol 'DistributedActor' is broken; cannot derive conformance for type 'D3'}}
24
+ // expected-error@-2{{protocol 'DistributedActor' is broken; cannot derive conformance for type 'D3'}} // FIXME(distributed): duplicate errors
25
+ // expected-error@-3{{type 'D3' does not conform to protocol 'Identifiable'}}
26
+ // expected-error@-4{{type 'D3' does not conform to protocol 'DistributedActor'}}
27
+ // expected-error@-5{{type 'D3' does not conform to protocol 'DistributedActor'}}
28
+
23
29
var id : Int { 0 }
24
30
// expected-error@-1{{property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
25
- // expected-error@-2{{invalid redeclaration of synthesized implementation for protocol requirement 'id'}}
31
+ // expected-error@-2{{invalid redeclaration of synthesized property 'id'}}
32
+ // expected-note@-3{{matching requirement 'id' to this declaration inferred associated type to 'Int'}}
26
33
}
27
34
35
+ struct OtherActorIdentity : Sendable , Hashable , Codable { }
36
+
28
37
distributed actor D4 {
29
38
// expected-error@-1{{actor 'D4' has no initializers}}
39
+ // expected-error@-2{{type 'D4' does not conform to protocol 'DistributedActor'}} // FIXME(distributed): duplicated errors
40
+ // expected-error@-3{{type 'D4' does not conform to protocol 'DistributedActor'}}
41
+ // expected-error@-4{{protocol 'DistributedActor' is broken; cannot derive conformance for type 'D4'}} // FIXME(distributed): duplicated errors
42
+ // expected-error@-5{{protocol 'DistributedActor' is broken; cannot derive conformance for type 'D4'}}
43
+ // expected-error@-6{{type 'D4' does not conform to protocol 'Identifiable'}}
30
44
let actorSystem : String
31
- // expected-error@-1{{invalid redeclaration of synthesized implementation for protocol requirement 'actorSystem'}}
45
+ // expected-error@-1{{invalid redeclaration of synthesized property 'actorSystem'}}
32
46
// expected-error@-2{{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
33
47
// expected-note@-3{{stored property 'actorSystem' without initial value prevents synthesized initializers}}
34
- let id : AnyActorIdentity
48
+ let id : OtherActorIdentity
35
49
// expected-error@-1{{property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
36
- // expected-note@-2{{stored property 'id' without initial value prevents synthesized initializers}}
50
+ // expected-error@-2{{invalid redeclaration of synthesized property 'id'}}
51
+ // expected-note@-3{{stored property 'id' without initial value prevents synthesized initializers}}
52
+ // expected-note@-4{{matching requirement 'id' to this declaration inferred associated type to 'OtherActorIdentity'}}
37
53
}
38
54
39
55
protocol P1 : DistributedActor {
@@ -57,3 +73,78 @@ func testConformance() {
57
73
acceptDistributedActor ( D1 . self)
58
74
acceptAnyActor ( D1 . self)
59
75
}
76
+
77
+
78
+ // ==== Fake Transport ---------------------------------------------------------
79
+
80
+ struct ActorAddress : Sendable , Hashable , Codable {
81
+ let address : String
82
+ init ( parse address: String ) {
83
+ self . address = address
84
+ }
85
+ }
86
+
87
+ // global to track available IDs
88
+ var nextID : Int = 1
89
+
90
+ struct FakeActorSystem : DistributedActorSystem {
91
+ public typealias ActorID = ActorAddress
92
+ public typealias Invocation = FakeInvocation
93
+ public typealias SerializationRequirement = Codable
94
+
95
+ init ( ) {
96
+ print ( " Initialized new FakeActorSystem " )
97
+ }
98
+
99
+ public func resolve< Act> ( id: ActorID , as actorType: Act . Type ) throws -> Act ?
100
+ where Act: DistributedActor ,
101
+ Act. ID == ActorID {
102
+ fatalError ( " not implemented: \( #function) " )
103
+ }
104
+
105
+ func assignID< Act> ( _ actorType: Act . Type ) -> ActorID
106
+ where Act: DistributedActor {
107
+ let id = ActorAddress ( parse: " \( nextID) " )
108
+ nextID += 1
109
+ print ( " assign type: \( actorType) , id: \( id) " )
110
+ return id
111
+ }
112
+
113
+ func actorReady< Act> ( _ actor : Act )
114
+ where Act: DistributedActor ,
115
+ Act. ID == ActorID {
116
+ print ( " ready actor: \( actor ) , id: \( actor . id) " )
117
+ }
118
+
119
+ func resignID( _ id: ActorID ) {
120
+ print ( " resign id: \( id) " )
121
+ }
122
+
123
+
124
+ public func makeInvocation( ) -> Invocation {
125
+ . init( )
126
+ }
127
+ }
128
+
129
+ public struct FakeInvocation : DistributedTargetInvocation {
130
+ public typealias ArgumentDecoder = FakeArgumentDecoder
131
+ public typealias SerializationRequirement = Codable
132
+
133
+ public mutating func recordGenericSubstitution< T> ( mangledType: T . Type ) throws { }
134
+ public mutating func recordArgument< Argument: SerializationRequirement > ( argument: Argument ) throws { }
135
+ public mutating func recordReturnType< R: SerializationRequirement > ( mangledType: R . Type ) throws { }
136
+ public mutating func recordErrorType< E: Error > ( mangledType: E . Type ) throws { }
137
+ public mutating func doneRecording( ) throws { }
138
+
139
+ // === Receiving / decoding -------------------------------------------------
140
+
141
+ public mutating func decodeGenericSubstitutions( ) throws -> [ Any . Type ] { [ ] }
142
+ public mutating func argumentDecoder( ) -> FakeArgumentDecoder { . init( ) }
143
+ public mutating func decodeReturnType( ) throws -> Any . Type ? { nil }
144
+ public mutating func decodeErrorType( ) throws -> Any . Type ? { nil }
145
+
146
+ public struct FakeArgumentDecoder : DistributedTargetInvocationArgumentDecoder {
147
+ public typealias SerializationRequirement = Codable
148
+ }
149
+ }
150
+
0 commit comments