Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare property default instance locations by id #180

Merged
merged 2 commits into from Mar 14, 2024

Conversation

davishmcclurg
Copy link
Owner

The keys used to collect property defaults are mutable hashes, which
causes weird hash table problems when they're modified (#hash no
longer matches even though they have the same #object_id).
Explained here: https://docs.ruby-lang.org/en/3.3/Hash.html#class-Hash-label-Modifying+an+Active+Hash+Key

I think this problem got covered up a bit because it requires more than
8 keys for values to be dropped.

compare_by_identity fixes things by just using #object_id to compare
hash keys. It stays consistent after the hash key is mutated.

From the docs:

Note: this requirement does not apply if the Hash uses
compare_by_identity since comparison will then rely on the keys'
object id instead of hash and eql?.

Fixes: #179

To be consistent with the rest of the codebase.
The keys used to collect property defaults are mutable hashes, which
causes weird hash table problems when they're modified (`#hash` no
longer matches even though they have the same `#object_id`).
Explained here: https://docs.ruby-lang.org/en/3.3/Hash.html#class-Hash-label-Modifying+an+Active+Hash+Key

I think this problem got covered up a bit because it requires more than
8 keys for values to be dropped.

`compare_by_identity` fixes things by just using `#object_id` to compare
hash keys. It stays consistent after the hash key is mutated.

From the [docs][0]:

> Note: this requirement does not apply if the Hash uses
> `compare_by_identity` since comparison will then rely on the keys'
> object id instead of `hash` and `eql?`.

Fixes: #179

[0]: https://docs.ruby-lang.org/en/3.3/Hash.html#class-Hash-label-User-Defined+Hash+Keys
@davishmcclurg davishmcclurg merged commit 002633b into main Mar 14, 2024
64 of 68 checks passed
@davishmcclurg davishmcclurg deleted the compare-instance-locations-by-identity branch March 14, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some properties with default values not inserted
1 participant