summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--array.c2
-rw-r--r--test/ruby/test_array.rb1
2 files changed, 2 insertions, 1 deletions
diff --git a/array.c b/array.c
index e21c011..1eb1d2e 100644
--- a/array.c
+++ b/array.c
@@ -1781,8 +1781,8 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
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);
}
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index d797ee8..6093893 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2121,6 +2121,7 @@ class TestArray < Test::Unit::TestCase
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)}