diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-12 03:03:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-12 03:03:46 +0000 |
commit | da786437a7be37f8807410a82071ace6089df97e (patch) | |
tree | 8302a6374caa4db335428cef5492e8f3f584d0e8 /test/ruby | |
parent | ff7bb4723b88ce6461ef6276a441fae4c69bd71d (diff) | |
download | ruby-da786437a7be37f8807410a82071ace6089df97e.tar.gz |
array.c: freeze in callback
* array.c (rb_ary_sort_bang): must not be modified once frozen even in
a callback method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_array.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 8a8af491c9..49628215b5 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1378,6 +1378,22 @@ class TestArray < Test::Unit::TestCase end end + def test_sort_bang_with_freeze + ary = [] + o1 = Object.new + o1.singleton_class.class_eval { + define_method(:<=>) {|v| + ary.freeze + 1 + } + } + o2 = o1.dup + ary << o1 << o2 + orig = ary.dup + assert_raise(RuntimeError, "frozen during comparison") {ary.sort!} + assert_equal(orig, ary, "must not be modified once frozen") + end + def test_to_a a = @cls[ 1, 2, 3 ] a_id = a.__id__ |