Skip to content

Commit 5073469

Browse files
committed
[Truffle] Return with block spec passes.
1 parent 39c9ca5 commit 5073469

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ public InjectNode(InjectNode prev) {
18381838
}
18391839

18401840
@Specialization(guards = "isObject")
1841-
public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
1841+
public Object injectObject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
18421842
int count = 0;
18431843

18441844
final Object[] store = (Object[]) array.getStore();
@@ -1862,6 +1862,25 @@ public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyPr
18621862
return accumulator;
18631863
}
18641864

1865+
@Specialization
1866+
public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
1867+
notDesignedForCompilation();
1868+
1869+
final Object[] store = array.slowToArray();
1870+
1871+
if (store.length < 2) {
1872+
throw new UnsupportedOperationException();
1873+
}
1874+
1875+
Object accumulator = initial;
1876+
1877+
for (int n = 0; n < array.getSize(); n++) {
1878+
accumulator = yield(frame, block, accumulator, store[n]);
1879+
}
1880+
1881+
return accumulator;
1882+
}
1883+
18651884
@Specialization
18661885
public Object inject(VirtualFrame frame, RubyArray array, RubySymbol symbol, UndefinedPlaceholder unused) {
18671886
notDesignedForCompilation();
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
fails:The return keyword invoked with a method call without parentheses with a block returns the value returned from the method call
21
fails:The return keyword in a Thread raises a LocalJumpError if used to exit a thread
32
fails:The return keyword within define_method stops at the method when the return is used directly

0 commit comments

Comments
 (0)