Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Sources/VexilMacros/FlagContainerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public enum FlagContainerMacro {}

extension FlagContainerMacro: MemberMacro {

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / visionOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / visionOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / iOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / iOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / watchOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / watchOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / tvOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / tvOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / macOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / macOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / macOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 21 in Sources/VexilMacros/FlagContainerMacro.swift

View workflow job for this annotation

GitHub Actions / macOS Matrix (26.1, macos-26)

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

public static func expansion(
of node: AttributeSyntax,
Expand Down Expand Up @@ -179,6 +179,17 @@
]
}

if shouldGenerateConformance.sendable {
decls += [
ExtensionDeclSyntax(
extendedType: type,
inheritanceClause: .init(inheritedTypes: [ .init(type: TypeSyntax(stringLiteral: "Sendable")) ])
) {
// Member block intentionally left blank
},
]
}

return decls
}

Expand Down Expand Up @@ -214,17 +225,14 @@

private extension [TypeSyntax] {

var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool) {
reduce(into: (false, false)) { result, type in
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool, sendable: Bool) {
reduce(into: (false, false, false)) { result, type in
if type.identifier == "FlagContainer" {
result = (true, result.1)
result = (true, result.1, result.2)
} else if type.identifier == "Equatable" {
result = (result.0, true)

// For some reason Swift 5.9 concatenates these into a single `IdentifierTypeSyntax`
// instead of providing them as array items
} else if type.identifier == "FlagContainerEquatable" {
result = (true, true)
result = (result.0, true, result.2)
} else if type.identifier == "Sendable" {
result = (result.0, result.1, true)
}
}
}
Expand All @@ -233,11 +241,11 @@

private extension AttributeSyntax {

var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool) {
var shouldGenerateConformance: (flagContainer: Bool, equatable: Bool, sendable: Bool) {
if attributeName.identifier == "FlagContainer" {
(true, true)
(true, true, true)
} else {
(false, false)
(false, false, false)
}
}

Expand Down
21 changes: 21 additions & 0 deletions Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
true
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -156,6 +159,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.otherStoredProperty == rhs.otherStoredProperty
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -231,6 +237,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.someFlag == rhs.someFlag
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -309,6 +318,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.someFlag == rhs.someFlag
}
}

extension SomeContainer.TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -383,6 +395,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.someFlag == rhs.someFlag
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -478,6 +493,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.second == rhs.second
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -572,6 +590,9 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
lhs.second == rhs.second
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down
12 changes: 12 additions & 0 deletions Tests/VexilMacroTests/FlagContainerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ final class FlagContainerMacroTests: XCTestCase {
true
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -99,6 +102,9 @@ final class FlagContainerMacroTests: XCTestCase {
true
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -142,6 +148,9 @@ final class FlagContainerMacroTests: XCTestCase {
true
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -238,6 +247,9 @@ final class FlagContainerMacroTests: XCTestCase {
lhs.second == rhs.second
}
}

extension TestFlags: Sendable {
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down
Loading