Actions
Bug #13558
closedArray#insert does not typecheck the position argument if it's the only argument
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
Backport:
Description
rb_ary_insert does this:
if (argc == 1) return ary;
For Ruby this means:
> [].insert("foo")
=> []
> [].insert(Exception.new)
=> []
I would expect this to raise a TypeError. The problem here is that if you forget the position argument, because perhaps you thought Array#insert would be an alias for Array#unshift, you get unexpected results and no errors.
If you try to insert two items it fails nicely:
> [].insert('foo', 'foo')
TypeError: no implicit conversion of String into Integer
Actions
Like0
Like0Like0Like0Like0