Project

General

Profile

Actions

Bug #13558

closed

Array#insert does not typecheck the position argument if it's the only argument

Added by kke (Kimmo Lehto) almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
[ruby-core:81125]

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

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58693.


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]
Actions #2

Updated by usa (Usaku NAKAMURA) over 6 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED

Updated by usa (Usaku NAKAMURA) over 6 years ago

  • Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: DONE, 2.4: REQUIRED

ruby_2_3 r59238 merged revision(s) 58693.

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • Backport changed from 2.2: WONTFIX, 2.3: DONE, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: DONE, 2.4: DONE

ruby_2_4 r59398 merged revision(s) 58693.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0