Skip to content

Commit

Permalink
[Truffle] Check if Array is frozen in Array#[]=.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 5, 2015
1 parent 5bc6093 commit c340849
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/element_set_tags.txt
Expand Up @@ -20,7 +20,6 @@ fails:Array#[]= tries to convert Range elements to Integers using #to_int with [
fails:Array#[]= raises an IndexError when passed indexes out of bounds
fails:Array#[]= calls to_ary on its rhs argument for multi-element sets
fails:Array#[]= does not call to_ary on rhs array subclasses for multi-element sets
fails:Array#[]= raises a RuntimeError on a frozen array
fails:Array#[]= with [index, count] returns non-array value if non-array value assigned
fails:Array#[]= with [index, count] returns array if array assigned
fails:Array#[]= with [index, count] just sets the section defined by [start,length] to nil even if the rhs is nil
Expand Down
Expand Up @@ -358,6 +358,8 @@ public IndexSetNode(IndexSetNode prev) {

@Specialization
public Object set(VirtualFrame frame, RubyArray array, int index, Object value, UndefinedPlaceholder unused) {
array.checkFrozen(this);

if (writeNode == null) {
CompilerDirectives.transferToInterpreter();
writeNode = insert(ArrayWriteDenormalizedNodeFactory.create(getContext(), getSourceSection(), null, null, null));
Expand All @@ -377,6 +379,8 @@ public Object setObject(VirtualFrame frame, RubyArray array, int start, int leng
throw new RaiseException(getContext().getCoreLibrary().indexNegativeLength(length, this));
}

array.checkFrozen(this);

final int begin = array.normalizeIndex(start);

if (begin >= array.getSize()) {
Expand All @@ -402,6 +406,8 @@ public Object setIntegerFixnum(VirtualFrame frame, RubyArray array, int start, i
throw new RaiseException(getContext().getCoreLibrary().indexNegativeLength(length, this));
}

array.checkFrozen(this);

if (value.getSize() == 0) {
final int begin = array.normalizeIndex(start);
final int exclusiveEnd = begin + length;
Expand All @@ -427,6 +433,8 @@ public Object setIntegerFixnum(VirtualFrame frame, RubyArray array, int start, i

@Specialization(guards = "isIntegerFixnum")
public Object setIntegerFixnumRange(VirtualFrame frame, RubyArray array, RubyRange.IntegerFixnumRange range, RubyArray other, UndefinedPlaceholder unused) {
array.checkFrozen(this);

if (range.doesExcludeEnd()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
Expand Down

0 comments on commit c340849

Please sign in to comment.