Skip to content

== implementation added in a macro is not considered when checking for Equatable conformance #66348

@JosephDuffy

Description

@JosephDuffy

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

Screenshot 2023-06-05 at 23 41 43 Screenshot 2023-06-05 at 23 41 58

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.swift macroFeature → declarations: Swift `macro` declarations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions