Actions
Bug #17736
closedDestructive methods inconsistently handle `receiver frozen state` in given block
Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
Description
When I interested around https://bugs.ruby-lang.org/issues/17735, I found following behaviors.
array = [1, 2, 3, 42]
array.select! do
array.freeze
false
end
p array #=> []
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]
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!.
Updated by nobu (Nobuyoshi Nakada) 26 days ago
- Status changed from Open to Closed
Applied in changeset git|e019dd24df4ed7063ad80d4c2e4070141793f598.
Ensure the receiver is modifiable before shrinking [Bug #17736]
Ensure the receiver is modifiable before shinking [Bug #17736]
Assert the receivers are not modified
Updated by nobu (Nobuyoshi Nakada) 26 days ago
- Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
Actions