Project

General

Profile

Actions

Bug #17736

closed

Destructive methods inconsistently handle `receiver frozen state` in given block

Added by kachick (Kenichi Kamiya) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
[ruby-core:102955]

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!.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0