-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Description
Writing a macro that outputs a ==
function is not considered when checking for Equatable
conformance.
Steps to reproduce
Write a macro conforming to ConformanceMacro
and MemberMacro
. Add Hashable
conformance via the expansion(of:providingConformancesOf:in:)
function and a valid static func ==
implementation via expansion(of:providingMembersOf:in:)
.
Expected behavior
The compiler should use the ==
function produced by the macro.
Screenshots


Environment
- swift-driver version: 1.82.2 Apple Swift version 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1)
- Xcode 15.0 (Build version 15A5160n)
- Deployment target:
- .macOS(.v10_15)
- .iOS(.v13)
- .tvOS(.v13)
- .watchOS(.v6)
- .macCatalyst(.v13)
Additional context
As shown in the screenshots the generated code looks right. Copy/pasting the generated code results in an "Invalid redeclaration of ==" error, then removing the ==
from the macro output allows the code to compile and the associated tests to pass, so I'm concluding (I hope correctly) that my implementation is correct!
It's also possible to workaround this issue by conforming to a custom protocol that adds a ==
function via extension.
I have an example of the workaround being used in a repo: https://github.com/JosephDuffy/CustomHashable. The remove-customHashable branch can be used to demonstrate the bug.
A topic I created on the Swift Forums a few weeks back for this: https://forums.swift.org/t/creating-a-macro-for-hashable-equatable-conformance/64711