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
16 changes: 8 additions & 8 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 / 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 / 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 / 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 / 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 / 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 @@ -78,11 +78,6 @@
shouldGenerateConformance.equatable = false
}

// We also can't generate Equatable conformance if there is no variables to generate them
if shouldGenerateConformance.equatable, declaration.memberBlock.variables.isEmpty {
shouldGenerateConformance.equatable = false
}

// Check that conformance doesn't already exist, or that we are inside a unit test.
// The latter is a workaround for https://github.com/apple/swift-syntax/issues/2031
guard shouldGenerateConformance.flagContainer else {
Expand Down Expand Up @@ -159,8 +154,8 @@
inheritanceClause: .init(inheritedTypes: [ .init(type: TypeSyntax(stringLiteral: "Equatable")) ])
) {
var variables = declaration.memberBlock.storedVariables
if variables.isEmpty == false {
try FunctionDeclSyntax("func ==(lhs: \(type), rhs: \(type)) -> Bool") {
try FunctionDeclSyntax("func ==(lhs: \(type), rhs: \(type)) -> Bool") {
if variables.isEmpty == false {
if let lastBinding = variables.removeLast().bindings.first?.pattern {
for variable in variables {
if let binding = variable.bindings.first?.pattern {
Expand All @@ -172,9 +167,14 @@
}
ExprSyntax("lhs.\(lastBinding.trimmed) == rhs.\(lastBinding.trimmed)")
}

// If there are no stored properties just return `true`. This matches the synthesised Equatable
// behaviour described in https://github.com/swiftlang/swift-evolution/blob/main/proposals/0185-synthesize-equatable-hashable.md#implementation-details
} else {
"true"
}
.with(\.modifiers, Array(scopes) + [ DeclModifierSyntax(name: .keyword(.static)) ])
}
.with(\.modifiers, Array(scopes) + [ DeclModifierSyntax(name: .keyword(.static)) ])
},
]
}
Expand Down
8 changes: 7 additions & 1 deletion Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest

final class EquatableFlagContainerMacroTests: XCTestCase {

func testDoesntGenerateWhenEmpty() throws {
func testGeneratesWhenEmpty() throws {
assertMacroExpansion(
"""
@FlagContainer
Expand Down Expand Up @@ -50,6 +50,12 @@ final class EquatableFlagContainerMacroTests: XCTestCase {
[:]
}
}

extension TestFlags: Equatable {
static func ==(lhs: TestFlags, rhs: TestFlags) -> Bool {
true
}
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down
18 changes: 18 additions & 0 deletions Tests/VexilMacroTests/FlagContainerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ final class FlagContainerMacroTests: XCTestCase {
[:]
}
}

extension TestFlags: Equatable {
static func ==(lhs: TestFlags, rhs: TestFlags) -> Bool {
true
}
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -87,6 +93,12 @@ final class FlagContainerMacroTests: XCTestCase {
[:]
}
}

extension TestFlags: Equatable {
public static func ==(lhs: TestFlags, rhs: TestFlags) -> Bool {
true
}
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down Expand Up @@ -124,6 +136,12 @@ final class FlagContainerMacroTests: XCTestCase {
[:]
}
}

extension TestFlags: Equatable {
static func ==(lhs: TestFlags, rhs: TestFlags) -> Bool {
true
}
}
""",
macros: [
"FlagContainer": FlagContainerMacro.self,
Expand Down
9 changes: 9 additions & 0 deletions Tests/VexilTests/EquatableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,13 @@ private struct DoubleSubgroupFlags {
@Flag("Third level test flag")
var thirdLevelFlag = false

@FlagGroup("Empty flags")
var empty: EmptyFlags

}

// Support for empty Flag Containers
@FlagContainer
private struct EmptyFlags {
// Intentionally left blank
}
Loading