* [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
@ 2022-11-09 0:04 jeremyevans0 (Jeremy Evans)
2022-11-09 20:21 ` [ruby-core:110672] " jeremyevans0 (Jeremy Evans)
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-11-09 0:04 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been reported by jeremyevans0 (Jeremy Evans).
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110672] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
@ 2022-11-09 20:21 ` jeremyevans0 (Jeremy Evans)
2022-11-15 7:38 ` [ruby-core:110759] " ko1 (Koichi Sasada)
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-11-09 20:21 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by jeremyevans0 (Jeremy Evans).
I think the following behavior makes the most sense:
* `Hash.[]` should never retain the compare_by_identity flag. It doesn't copy the default value/proc, so retaining the compare_by_identity flag does not make sense.
* `Hash.ruby2_keywords_hash` should always retain the compare_by_identity flag. It copies the default value/proc, so retaining the compare_by_identity flag makes sense.
* `Hash#compact` should copy the default value/proc and retain the compare_by_identity flag. It currently does neither. However, the documentation says it returns a copy of the receiver, which implies the result should have the same default value/proc and compare_by_identity flag as the receiver.
I've submitted a pull request for these changes: https://github.com/ruby/ruby/pull/6702
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100014
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110759] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
2022-11-09 20:21 ` [ruby-core:110672] " jeremyevans0 (Jeremy Evans)
@ 2022-11-15 7:38 ` ko1 (Koichi Sasada)
2022-11-18 17:03 ` [ruby-core:110812] " headius (Charles Nutter)
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ko1 (Koichi Sasada) @ 2022-11-15 7:38 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by ko1 (Koichi Sasada).
I think `Hash[]` remains all keys on the new Hash so `compare_by_identity` should be remained.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100099
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110812] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
2022-11-09 20:21 ` [ruby-core:110672] " jeremyevans0 (Jeremy Evans)
2022-11-15 7:38 ` [ruby-core:110759] " ko1 (Koichi Sasada)
@ 2022-11-18 17:03 ` headius (Charles Nutter)
2022-11-18 17:03 ` [ruby-core:110813] " headius (Charles Nutter)
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: headius (Charles Nutter) @ 2022-11-18 17:03 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by headius (Charles Nutter).
jeremyevans0 (Jeremy Evans) wrote in #note-1:
> I think the following behavior makes the most sense:
>
> * `Hash.[]` should never retain the compare_by_identity flag. It doesn't copy the default value/proc, so retaining the compare_by_identity flag does not make sense.
I disagree. The contents of the other hash will have been populated using identity comparison rather than equality comparison. If that characteristic does not propagate to the new hash, any == keys will collide or else the set of keys will have to change. Is `Hash.[]` intended to make a copy, or a new hash populated with a subset of the original keys using non-identity, non-default semantics?
I agree with your other points.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100170
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110813] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (2 preceding siblings ...)
2022-11-18 17:03 ` [ruby-core:110812] " headius (Charles Nutter)
@ 2022-11-18 17:03 ` headius (Charles Nutter)
2022-11-18 17:32 ` [ruby-core:110814] " jeremyevans0 (Jeremy Evans)
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: headius (Charles Nutter) @ 2022-11-18 17:03 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by headius (Charles Nutter).
FWIW I ran into this while implementing Ruby 3.1 identhash semantics in JRuby, and then realized this is now one of the few "copy" paths that does not propagate identity comparison.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100171
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110814] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (3 preceding siblings ...)
2022-11-18 17:03 ` [ruby-core:110813] " headius (Charles Nutter)
@ 2022-11-18 17:32 ` jeremyevans0 (Jeremy Evans)
2022-11-18 18:37 ` [ruby-core:110815] " headius (Charles Nutter)
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-11-18 17:32 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by jeremyevans0 (Jeremy Evans).
headius (Charles Nutter) wrote in #note-3:
> jeremyevans0 (Jeremy Evans) wrote in #note-1:
> > I think the following behavior makes the most sense:
> >
> > * `Hash.[]` should never retain the compare_by_identity flag. It doesn't copy the default value/proc, so retaining the compare_by_identity flag does not make sense.
>
> I disagree. The contents of the other hash will have been populated using identity comparison rather than equality comparison. If that characteristic does not propagate to the new hash, any == keys will collide or else the set of keys will have to change. Is `Hash.[]` intended to make a copy, or a new hash populated with a subset of the original keys using non-identity, non-default semantics?
It's explicitly documented as returning a new hash, not a copy: `Returns a new Hash object populated with the given objects`.
The fact that it doesn't copy the default value/proc indicates to me that the compare_by_identity flag should not be copied either. However, I don't feel strongly regarding this. We can make it so the compare_by_identity flag is always copied. We do need to make some change, because the current behavior is inconsistent.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100172
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110815] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (4 preceding siblings ...)
2022-11-18 17:32 ` [ruby-core:110814] " jeremyevans0 (Jeremy Evans)
@ 2022-11-18 18:37 ` headius (Charles Nutter)
2022-11-18 18:57 ` [ruby-core:110816] " jeremyevans0 (Jeremy Evans)
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: headius (Charles Nutter) @ 2022-11-18 18:37 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by headius (Charles Nutter).
Even though it's a "new Hash", it is supposed to be populated with "the given objects". If losing identity comparison means some keys don't get populated, I would consider that broken.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100173
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110816] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (5 preceding siblings ...)
2022-11-18 18:37 ` [ruby-core:110815] " headius (Charles Nutter)
@ 2022-11-18 18:57 ` jeremyevans0 (Jeremy Evans)
2022-11-18 19:47 ` [ruby-core:110817] " Eregon (Benoit Daloze)
2022-12-23 2:39 ` [ruby-core:111389] " matz (Yukihiro Matsumoto) via ruby-core
8 siblings, 0 replies; 10+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-11-18 18:57 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by jeremyevans0 (Jeremy Evans).
headius (Charles Nutter) wrote in #note-6:
> Even though it's a "new Hash", it is supposed to be populated with "the given objects". If losing identity comparison means some keys don't get populated, I would consider that broken.
If you turn the hash into an array, you have the same `given objects`, but different results:
```ruby
h = {'a'=>1}.compare_by_identity
h['a'] = 2
Hash[h] # {'a'=>1, 'a'=>2}.compare_by_identity
Hash[h.to_a] # {'a'=>2}
```
Not respecting the compare_by_identity flag (as my PR does) would make `Hash[h] == Hash[h.to_a]`.
I would say that `populated with the given objects` does not imply `resulting in the same set of keys.` Also, `given objects` (not `given object`) implies it looks at the content of the hash, but not the hash object itself (hence why default value/proc is not copied).
Here's the pseudocode I would consider based on the documentation:
```ruby
# new hash
output_hash = {}
# populated with the given objects
input_hash_or_array.each do |k, v|
output_hash[k] = v
end
output_hash
```
There are certainly valid arguments for both sides, so we'll have to see what @matz decides.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100174
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:110817] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (6 preceding siblings ...)
2022-11-18 18:57 ` [ruby-core:110816] " jeremyevans0 (Jeremy Evans)
@ 2022-11-18 19:47 ` Eregon (Benoit Daloze)
2022-12-23 2:39 ` [ruby-core:111389] " matz (Yukihiro Matsumoto) via ruby-core
8 siblings, 0 replies; 10+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-11-18 19:47 UTC (permalink / raw)
To: ruby-core
Issue #19113 has been updated by Eregon (Benoit Daloze).
The way I see it, `Hash[*args]` converts args to a Hash, and args is only considered as key-value pairs. So if `args = [some_Hash]`, it's just one of the representation of key-value pairs but the behavior shouldn't be special with a Hash argument otherwise.
IOW I agree with Jeremy here. To copy a Hash there is `.dup`/`.clone`.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100175
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:111389] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
` (7 preceding siblings ...)
2022-11-18 19:47 ` [ruby-core:110817] " Eregon (Benoit Daloze)
@ 2022-12-23 2:39 ` matz (Yukihiro Matsumoto) via ruby-core
8 siblings, 0 replies; 10+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2022-12-23 2:39 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #19113 has been updated by matz (Yukihiro Matsumoto).
I agree with @jeremyevans0 too.
Matz.
----------------------------------------
Bug #19113: Inconsistency in retention of compare_by_identity flag in Hash methods
https://bugs.ruby-lang.org/issues/19113#change-100764
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Hash.[]` and `Hash.ruby2_keywords_hash` retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
```ruby
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
```
This inconsistency seems like a bug.
`Hash#compact` always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
```ruby
{}.compare_by_identity.compact.compare_by_identity?
# => false
```
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-12-23 2:39 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 0:04 [ruby-core:110663] [Ruby master Bug#19113] Inconsistency in retention of compare_by_identity flag in Hash methods jeremyevans0 (Jeremy Evans)
2022-11-09 20:21 ` [ruby-core:110672] " jeremyevans0 (Jeremy Evans)
2022-11-15 7:38 ` [ruby-core:110759] " ko1 (Koichi Sasada)
2022-11-18 17:03 ` [ruby-core:110812] " headius (Charles Nutter)
2022-11-18 17:03 ` [ruby-core:110813] " headius (Charles Nutter)
2022-11-18 17:32 ` [ruby-core:110814] " jeremyevans0 (Jeremy Evans)
2022-11-18 18:37 ` [ruby-core:110815] " headius (Charles Nutter)
2022-11-18 18:57 ` [ruby-core:110816] " jeremyevans0 (Jeremy Evans)
2022-11-18 19:47 ` [ruby-core:110817] " Eregon (Benoit Daloze)
2022-12-23 2:39 ` [ruby-core:111389] " matz (Yukihiro Matsumoto) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).