Skip to content

Commit 938572d

Browse files
authored
Merge pull request #142 from unsignedapps/fix/vexil3/sendable
Generate explicit Sendable conformance
2 parents f8a9179 + 96d8632 commit 938572d

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

Sources/VexilMacros/FlagContainerMacro.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ extension FlagContainerMacro: ExtensionMacro {
179179
]
180180
}
181181

182+
if shouldGenerateConformance.sendable {
183+
decls += [
184+
ExtensionDeclSyntax(
185+
extendedType: type,
186+
inheritanceClause: .init(inheritedTypes: [ .init(type: TypeSyntax(stringLiteral: "Sendable")) ])
187+
) {
188+
// Member block intentionally left blank
189+
},
190+
]
191+
}
192+
182193
return decls
183194
}
184195

@@ -214,17 +225,14 @@ private extension TypeSyntax {
214225

215226
private extension [TypeSyntax] {
216227

217-
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool) {
218-
reduce(into: (false, false)) { result, type in
228+
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool, sendable: Bool) {
229+
reduce(into: (false, false, false)) { result, type in
219230
if type.identifier == "FlagContainer" {
220-
result = (true, result.1)
231+
result = (true, result.1, result.2)
221232
} else if type.identifier == "Equatable" {
222-
result = (result.0, true)
223-
224-
// For some reason Swift 5.9 concatenates these into a single `IdentifierTypeSyntax`
225-
// instead of providing them as array items
226-
} else if type.identifier == "FlagContainerEquatable" {
227-
result = (true, true)
233+
result = (result.0, true, result.2)
234+
} else if type.identifier == "Sendable" {
235+
result = (result.0, result.1, true)
228236
}
229237
}
230238
}
@@ -233,11 +241,11 @@ private extension [TypeSyntax] {
233241

234242
private extension AttributeSyntax {
235243

236-
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool) {
244+
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool, sendable: Bool) {
237245
if attributeName.identifier == "FlagContainer" {
238-
(true, true)
246+
(true, true, true)
239247
} else {
240-
(false, false)
248+
(false, false, false)
241249
}
242250
}
243251

Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
5656
true
5757
}
5858
}
59+
60+
extension TestFlags: Sendable {
61+
}
5962
""",
6063
macros: [
6164
"FlagContainer": FlagContainerMacro.self,
@@ -156,6 +159,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
156159
lhs.otherStoredProperty == rhs.otherStoredProperty
157160
}
158161
}
162+
163+
extension TestFlags: Sendable {
164+
}
159165
""",
160166
macros: [
161167
"FlagContainer": FlagContainerMacro.self,
@@ -231,6 +237,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
231237
lhs.someFlag == rhs.someFlag
232238
}
233239
}
240+
241+
extension TestFlags: Sendable {
242+
}
234243
""",
235244
macros: [
236245
"FlagContainer": FlagContainerMacro.self,
@@ -309,6 +318,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
309318
lhs.someFlag == rhs.someFlag
310319
}
311320
}
321+
322+
extension SomeContainer.TestFlags: Sendable {
323+
}
312324
""",
313325
macros: [
314326
"FlagContainer": FlagContainerMacro.self,
@@ -383,6 +395,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
383395
lhs.someFlag == rhs.someFlag
384396
}
385397
}
398+
399+
extension TestFlags: Sendable {
400+
}
386401
""",
387402
macros: [
388403
"FlagContainer": FlagContainerMacro.self,
@@ -478,6 +493,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
478493
lhs.second == rhs.second
479494
}
480495
}
496+
497+
extension TestFlags: Sendable {
498+
}
481499
""",
482500
macros: [
483501
"FlagContainer": FlagContainerMacro.self,
@@ -572,6 +590,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
572590
lhs.second == rhs.second
573591
}
574592
}
593+
594+
extension TestFlags: Sendable {
595+
}
575596
""",
576597
macros: [
577598
"FlagContainer": FlagContainerMacro.self,

Tests/VexilMacroTests/FlagContainerMacroTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ final class FlagContainerMacroTests: XCTestCase {
5656
true
5757
}
5858
}
59+
60+
extension TestFlags: Sendable {
61+
}
5962
""",
6063
macros: [
6164
"FlagContainer": FlagContainerMacro.self,
@@ -99,6 +102,9 @@ final class FlagContainerMacroTests: XCTestCase {
99102
true
100103
}
101104
}
105+
106+
extension TestFlags: Sendable {
107+
}
102108
""",
103109
macros: [
104110
"FlagContainer": FlagContainerMacro.self,
@@ -142,6 +148,9 @@ final class FlagContainerMacroTests: XCTestCase {
142148
true
143149
}
144150
}
151+
152+
extension TestFlags: Sendable {
153+
}
145154
""",
146155
macros: [
147156
"FlagContainer": FlagContainerMacro.self,
@@ -238,6 +247,9 @@ final class FlagContainerMacroTests: XCTestCase {
238247
lhs.second == rhs.second
239248
}
240249
}
250+
251+
extension TestFlags: Sendable {
252+
}
241253
""",
242254
macros: [
243255
"FlagContainer": FlagContainerMacro.self,

0 commit comments

Comments
 (0)