Skip to content

Commit

Permalink
Array#delete should delete the first object *inside* the array,
Browse files Browse the repository at this point in the history
not the one that is given as the argument to it, even when the objects
are equal via '=='.

This fixes #411.
  • Loading branch information
BanzaiMan committed Nov 26, 2012
1 parent aa2e98c commit fe138bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/org/jruby/RubyArray.java
Expand Up @@ -2459,13 +2459,17 @@ public IRubyObject keep_if(ThreadContext context, Block block) {
@JRubyMethod(required = 1)
public IRubyObject delete(ThreadContext context, IRubyObject item, Block block) {
int i2 = 0;
IRubyObject value = item;

Ruby runtime = context.runtime;
for (int i1 = 0; i1 < realLength; i1++) {
// Do not coarsen the "safe" check, since it will misinterpret AIOOBE from equalInternal
// See JRUBY-5434
IRubyObject e = safeArrayRef(values, begin + i1);
if (equalInternal(context, e, item)) continue;
if (equalInternal(context, e, item)) {
value = e;
continue;
}
if (i1 != i2) store(i2, e);
i2++;
}
Expand All @@ -2492,7 +2496,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject item, Block block)
concurrentModification();
}

return item;
return value;
}

/** rb_ary_delete_at
Expand Down

0 comments on commit fe138bf

Please sign in to comment.