Skip to content

feat(minor): report non-Equatable properties on the property and compare classes by identity - #42

Merged
supersonicbyte merged 2 commits into
mainfrom
feat/improve-equatable-on-class-types
Nov 7, 2026
Merged

supersonicbyte merged 2 commits into
mainfrom
feat/improve-equatable-on-class-types

Conversation

@supersonicbyte

Copy link
Copy Markdown
Collaborator

Description

Macros only see syntax, so @Equatable could not tell whether a property
type conforms to Equatable; the error appeared inside the generated ==.
The macro now attaches @_EquatableCheck to every compared property. That
peer macro is overloaded on its argument's constraints, so the compiler
resolves Equatable types and classes to a no-op expansion and everything
else to one that reports the error on the property with a fix-it for
@EquatableIgnored.

The generated == and hash(into:) call the overloaded _$isEqual and
_$hash helpers instead of == and hasher.combine, so classes that are
not Equatable are compared with === and hashed by ObjectIdentifier,
while Equatable classes keep their own ==. An Equatable class that is
not Hashable contributes nothing to the hash; hashing it by identity would
break the Hashable contract, and an unavailable overload is skipped by
overload resolution rather than reported.

Technique from https://www.pointfree.co/blog/posts/232-advanced-macro-technique-1-static-type-information

Refs #40, #32

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Minimal checklist:

  • I have performed a self-review of my own code
  • I have added DocC code-level documentation for any public interfaces exported by the package
  • I have added unit and/or integration tests that prove my fix is effective or that my feature works

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@supersonicbyte supersonicbyte self-assigned this Oct 13, 2026
@ThePreppy

Copy link
Copy Markdown
Contributor

Hi @supersonicbyte @hassila,
Hope you both are doing well :)

A similar set of capabilities was introduced by this PR, but it also adds a lot of customisation to how the user wants equatable conformance to be derived.

Could you please check it out?
#39

@supersonicbyte
supersonicbyte force-pushed the feat/improve-equatable-on-class-types branch from 1365cda to c011842 Compare October 20, 2026 10:13
@supersonicbyte

Copy link
Copy Markdown
Collaborator Author

Hi @supersonicbyte @hassila, Hope you both are doing well :)

A similar set of capabilities was introduced by this PR, but it also adds a lot of customisation to how the user wants equatable conformance to be derived.

Could you please check it out? #39

Hi @ThePreppy sorry for the wait, it's merged! Thanks for contributing!

@hassila

hassila commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

@supersonicbyte close this one then?

@supersonicbyte

Copy link
Copy Markdown
Collaborator Author

@supersonicbyte close this one then?

I rebased this one with #39. It has changes for better diagnostics + automatic detection of class types and comparing them by identity (===).

@hassila
hassila requested a review from axelandersson November 7, 2026 08:26
@supersonicbyte
supersonicbyte merged commit d4e3e63 into main Nov 7, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants