ruby-changes:46577
From: nobu <ko1@a...>
Date: Sat, 13 May 2017 02:02:52 +0900 (JST)
Subject: [ruby-changes:46577] nobu:r58693 (trunk): array.c: check position to insert
nobu 2017-05-13 02:02:48 +0900 (Sat, 13 May 2017) New Revision: 58693 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58693 Log: array.c: check position to insert * array.c (rb_ary_insert): check position to insert even if no elements to be inserted. [ruby-core:81125] [Bug #13558] Modified files: trunk/array.c trunk/test/ruby/test_array.rb Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 58692) +++ test/ruby/test_array.rb (revision 58693) @@ -2121,6 +2121,7 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2121 assert_equal([0], a.insert(1)) assert_equal([0, 1], a.insert(1, 1)) assert_raise(ArgumentError) { a.insert } + assert_raise(TypeError) { a.insert(Object.new) } assert_equal([0, 1, 2], a.insert(-1, 2)) assert_equal([0, 1, 3, 2], a.insert(-2, 3)) assert_raise(RuntimeError) { [0].freeze.insert(0)} Index: array.c =================================================================== --- array.c (revision 58692) +++ array.c (revision 58693) @@ -1781,8 +1781,8 @@ rb_ary_insert(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/array.c#L1781 rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); rb_ary_modify_check(ary); - if (argc == 1) return ary; pos = NUM2LONG(argv[0]); + if (argc == 1) return ary; if (pos == -1) { pos = RARRAY_LEN(ary); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/