The provided implementation of IndexCollection implements toArray by simply returning the internal Array. This means that any change done to the Array returned will actually change the contents of the IndexCollection itself. Right now, this really causes no issue, but it is possible that other implementations may not react well to that.
It should be clearly defined whether IndexCollection implementations should enforce mutability through the Array returned from toArray or prevent it. Otherwise, code utilizing the current mutable implementation could break if moving to an implementation where that mutability is not upheld or behaviour is undefined for attempting to mutate in that fashion.
The provided implementation of
IndexCollection
implementstoArray
by simply returning the internalArray
. This means that any change done to theArray
returned will actually change the contents of theIndexCollection
itself. Right now, this really causes no issue, but it is possible that other implementations may not react well to that.It should be clearly defined whether
IndexCollection
implementations should enforce mutability through theArray
returned fromtoArray
or prevent it. Otherwise, code utilizing the current mutable implementation could break if moving to an implementation where that mutability is not upheld or behaviour is undefined for attempting to mutate in that fashion.