Skip to content

Commit

Permalink
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/element_set_tags.txt

This file was deleted.

19 changes: 14 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -392,17 +392,26 @@ public Object set(VirtualFrame frame, DynamicObject array, Object indexObject, O
@Specialization(guards = { "!isRubyArray(value)", "wasProvided(value)", "strategy.specializesFor(value)" }, limit = "ARRAY_STRATEGIES")
public Object setObject(VirtualFrame frame, DynamicObject array, int start, int length, Object value,
@Cached("forValue(value)") ArrayStrategy strategy,
@Cached("createBinaryProfile()") ConditionProfile negativeIndexProfile) {
@Cached("createBinaryProfile()") ConditionProfile negativeIndexProfile,
@Cached("new()") SnippetNode snippetNode) {
checkLengthPositive(length);

final int size = getSize(array);
final int begin = ArrayOperations.normalizeIndex(size, start, negativeIndexProfile);
checkIndex(array, start, begin);

// Passing a non-array as value is the same as assigning a single-element array
ArrayMirror mirror = strategy.newArray(1);
mirror.set(0, value);
DynamicObject ary = createArray(getContext(), mirror.getArray(), 1);
final DynamicObject ary;

final Object maybeAry = snippetNode.execute(frame, "Array.try_convert(value)", "value", value);
if (maybeAry != nil()) {
ary = (DynamicObject) maybeAry;
} else {
// Passing a non-array as value is the same as assigning a single-element array
ArrayMirror mirror = strategy.newArray(1);
mirror.set(0, value);
ary = createArray(getContext(), mirror.getArray(), 1);
}

return executeSet(frame, array, start, length, ary);
}

0 comments on commit 180000c

Please sign in to comment.