Skip to content

Commit b8bbc8a

Browse files
authored
Merge pull request #67679 from xedin/fix-distributed-actor-init-synthesis
[TypeChecker] Make sure that distributed actors always get "default" init
2 parents 03334a8 + e2bac24 commit b8bbc8a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,12 @@ HasDefaultInitRequest::evaluate(Evaluator &evaluator,
14901490
if (hasUserDefinedDesignatedInit(evaluator, decl))
14911491
return false;
14921492

1493+
// Regardless of whether all of the properties are initialized or
1494+
// not distributed actors always get a special "default" init based
1495+
// on `id` and `actorSystem` synthesized properties.
1496+
if (decl->isDistributedActor())
1497+
return true;
1498+
14931499
// We can only synthesize a default init if all the stored properties have an
14941500
// initial value.
14951501
return areAllStoredPropertiesDefaultInitializable(evaluator, decl);

test/decl/protocol/special/DistributedActor.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ extension DAP where ActorSystem.ActorID == String {
3535
}
3636

3737
distributed actor D2 {
38-
// expected-error@-1{{actor 'D2' has no initializers}}
3938
let actorSystem: String
4039
// expected-error@-1{{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
41-
// expected-note@-2{{stored property 'actorSystem' without initial value prevents synthesized initializers}}
4240
}
4341

4442
distributed actor D3 {
@@ -49,14 +47,10 @@ distributed actor D3 {
4947
struct OtherActorIdentity: Sendable, Hashable, Codable {}
5048

5149
distributed actor D4 {
52-
// expected-error@-1{{actor 'D4' has no initializers}}
53-
5450
let actorSystem: String
5551
// expected-error@-1{{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
56-
// expected-note@-2{{stored property 'actorSystem' without initial value prevents synthesized initializers}}
5752
let id: OtherActorIdentity
5853
// expected-error@-1{{property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}}
59-
// expected-note@-2{{stored property 'id' without initial value prevents synthesized initializers}}
6054
}
6155

6256
protocol P1: DistributedActor {

0 commit comments

Comments
 (0)