Repository navigation
feat(minor): report non-Equatable properties on the property and compare classes by identity - #42
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Hi @supersonicbyte @hassila, 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? |
…are classes by identity
1365cda to
c011842
Compare
Hi @ThePreppy sorry for the wait, it's merged! Thanks for contributing! |
|
@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 ( |
Description
Macros only see syntax, so
@Equatablecould not tell whether a propertytype conforms to
Equatable; the error appeared inside the generated==.The macro now attaches
@_EquatableCheckto every compared property. Thatpeer macro is overloaded on its argument's constraints, so the compiler
resolves
Equatabletypes and classes to a no-op expansion and everythingelse to one that reports the error on the property with a fix-it for
@EquatableIgnored.The generated
==andhash(into:)call the overloaded_$isEqualand_$hashhelpers instead of==andhasher.combine, so classes that arenot
Equatableare compared with===and hashed byObjectIdentifier,while
Equatableclasses keep their own==. AnEquatableclass that isnot
Hashablecontributes nothing to the hash; hashing it by identity wouldbreak the
Hashablecontract, and an unavailable overload is skipped byoverload 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:
DocCcode-level documentation for any public interfaces exported by the package