Project

General

Profile

Actions

Bug #17736

closed

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

Added by kachick (Kenichi Kamiya) almost 4 years ago. Updated over 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 #1

Updated by nobu (Nobuyoshi Nakada) almost 4 years 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

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 4 years 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

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE

ruby_3_0 44b87adc07621b6a8eddfcf4aaff34ce634179d4 merged revision(s) e019dd24df4ed7063ad80d4c2e4070141793f598,7954bb056be30e86c419fe3792064d28990a4999,7d3fdfb27dac456827b004d9e66a44b15f8cd762.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0