Issue #17739 has been updated by matz (Yukihiro Matsumoto).


Accepted. I have small concerns about performance (in microbenchmarks). But I don't think I have another choice.

Matz.


----------------------------------------
Bug #17739: Array#sort! changes the order even if the receiver raises FrozenError in given block
https://bugs.ruby-lang.org/issues/17739#change-92070

* 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
----------------------------------------
I think this is a similar issue of https://bugs.ruby-lang.org/issues/17736

```ruby
array = [1, 2, 3, 4, 5]
begin
  array.sort! do |a, b|
    array.freeze if a == 3
    1
  end
rescue => err
  p err #=> #<FrozenError: can't modify frozen Array: [5, 4, 3, 2, 1]>
end
p array #=> [5, 4, 3, 2, 1]

array = [1, 2, 3, 4, 5]
array.sort! do |a, b|
  break if a == 3
  1
end
p array #=> [3, 4, 2, 1, 5]
```

Array#sort! raises a FrozenError as expected, but the order is changed. I would expect the order is kept after frozen. 



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