[ruby-core:102955] [Ruby master Bug#17736] Destructive methods inconsistently handle `receiver frozen state` in given block
From:
kachick1@...
Date:
2021-03-20 07:12:12 UTC
List:
ruby-core #102955
Issue #17736 has been reported by kachick (Kenichi Kamiya).
----------------------------------------
Bug #17736: Destructive methods inconsistently handle `receiver frozen state` in given block
https://bugs.ruby-lang.org/issues/17736
* Author: kachick (Kenichi Kamiya)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
When I interested around https://bugs.ruby-lang.org/issues/17735, I found following behaviors.
```ruby
array = [1, 2, 3, 42]
array.select! do
array.freeze
false
end
p array #=> []
```
```ruby
array = [1, 2, 3, 42, 2, 3]
begin
array.uniq! do |item|
array.freeze
item
end
rescue => err
p err #=> #<FrozenError: can't modify frozen Array: [1, 2, 3, 42, 2, 3]>
end
p array #=> [1, 2, 3, 42, 2, 3]
```
```ruby
hash = {a: 1, b: 2, c: 3}
hash.select! do
hash.freeze
false
end
p hash #=> {}
```
Is this an intentional behavior?
I would expect `To raise FrozenError` and `Does not modify receiver after frozen` like Array#uniq!.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>