@@ -36,6 +36,12 @@ extension DistributedProtocolMacro {
36
36
in context: some MacroExpansionContext
37
37
) throws -> [ ExtensionDeclSyntax ] {
38
38
guard let proto = declaration. as ( ProtocolDeclSyntax . self) else {
39
+ // we diagnose here, only once
40
+ try throwIllegalTargetDecl ( node: node, declaration)
41
+ }
42
+
43
+ guard !proto. memberBlock. members. isEmpty else {
44
+ // ok, the protocol has no requirements so we no-op it
39
45
return [ ]
40
46
}
41
47
@@ -44,17 +50,7 @@ extension DistributedProtocolMacro {
44
50
member. trimmed
45
51
}
46
52
let requirementStubs = requirements
47
- . map { req in
48
- """
49
- \( req) {
50
- if #available(SwiftStdlib 6.0, *) {
51
- Distributed._distributedStubFatalError()
52
- } else {
53
- fatalError()
54
- }
55
- }
56
- """
57
- } . joined ( separator: " \n " )
53
+ . map ( stubMethod) . joined ( separator: " \n " )
58
54
59
55
let extensionDecl : DeclSyntax =
60
56
"""
@@ -64,6 +60,24 @@ extension DistributedProtocolMacro {
64
60
"""
65
61
return [ extensionDecl. cast ( ExtensionDeclSyntax . self) ]
66
62
}
63
+
64
+ static func stubMethod( _ requirementDeclaration: MemberBlockItemListSyntax . Element ) -> String {
65
+ """
66
+ \( requirementDeclaration) {
67
+ \( stubFunctionBody ( ) )
68
+ }
69
+ """
70
+ }
71
+
72
+ static func stubFunctionBody( ) -> DeclSyntax {
73
+ """
74
+ if #available(SwiftStdlib 6.0, *) {
75
+ Distributed._distributedStubFatalError()
76
+ } else {
77
+ fatalError()
78
+ }
79
+ """
80
+ }
67
81
}
68
82
69
83
// ===== -----------------------------------------------------------------------
@@ -76,15 +90,30 @@ extension DistributedProtocolMacro {
76
90
in context: some MacroExpansionContext
77
91
) throws -> [ DeclSyntax ] {
78
92
guard let proto = declaration. as ( ProtocolDeclSyntax . self) else {
79
- try throwIllegalTargetDecl ( node: node, declaration)
93
+ // don't diagnose here (again),
94
+ // we'll already report an error here from the other macro role
95
+ return [ ]
80
96
}
81
97
82
98
var isGenericStub = false
83
99
var specificActorSystemRequirement : TypeSyntax ?
84
100
// FIXME must detect this off the protocol
85
101
let serializationRequirementType : String = " Codable "
86
102
87
- for req in proto. genericWhereClause? . requirements ?? [ ] {
103
+ guard let genericWhereClause = proto. genericWhereClause else {
104
+ guard !proto. memberBlock. members. isEmpty else {
105
+ // ok, the protocol has no requirements so we no-op it
106
+ return [ ]
107
+ }
108
+ throw DiagnosticsError (
109
+ syntax: node,
110
+ message: """
111
+ Distributed protocol must declare actor system with SerializationRequirement, for example:
112
+ protocol Greeter<ActorSystem>: DistributedActor where ActorSystem: DistributedActorSystem<any Codable>
113
+ """ , id: . invalidApplication)
114
+ }
115
+
116
+ for req in genericWhereClause. requirements {
88
117
print ( " req.requirement: \( req. requirement) " )
89
118
switch req. requirement {
90
119
case . conformanceRequirement( let conformanceReq)
@@ -125,7 +154,7 @@ extension DistributedProtocolMacro {
125
154
} else {
126
155
throw DiagnosticsError (
127
156
syntax: node,
128
- message: " '@DistributedProtocolMacro ' cannot be applied to " , id: . invalidApplication)
157
+ message: " '@DistributedProtocol ' cannot be applied to " , id: . invalidApplication)
129
158
}
130
159
131
160
return [ stubActorDecl]
0 commit comments