Skip to content

Commit

Permalink
[Truffle] Fix Array#inject when ary.length < 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Mar 5, 2015
1 parent b272789 commit 28030d0
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -1334,10 +1334,6 @@ public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyPr

final Object[] store = array.slowToArray();

if (store.length < 2) {
throw new UnsupportedOperationException();
}

Object accumulator = initial;

for (int n = 0; n < array.getSize(); n++) {
Expand All @@ -1354,7 +1350,11 @@ public Object inject(VirtualFrame frame, RubyArray array, RubySymbol symbol, Und
final Object[] store = array.slowToArray();

if (store.length < 2) {
throw new UnsupportedOperationException();
if (store.length == 1) {
return store[0];
} else {
return getContext().getCoreLibrary().getNilObject();
}
}

Object accumulator = dispatch.call(frame, store[0], symbol, null, store[1]);
Expand Down

0 comments on commit 28030d0

Please sign in to comment.