# Error writing into a view of an array using CartesianIndices

**URL:** <https://discourse.julialang.org/t/error-writing-into-a-view-of-an-array-using-cartesianindices/16738>\
**Category:** General Usage\
**Tags:** question, indexing\
**Created:** [October 24, 2018, 2:18pm UTC](https://discourse.julialang.org/t/error-writing-into-a-view-of-an-array-using-cartesianindices/16738 "2018-10-24T14:18:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [October 24, 2018, 2:18pm UTC](https://discourse.julialang.org/t/error-writing-into-a-view-of-an-array-using-cartesianindices/16738/1 "2018-10-24T14:18:10Z")

</div>

In Julia 0.7 I get an error in the following code:

```julia
a=rand(10,10)
index1 = CartesianIndices((1:2,1:2))
index2 = CartesianIndices((1:2,1:2))
a1 = view(a,index1)
a1[index2]=rand(2,2)

```

```julia
ArgumentError: an array of type `CartesianIndices` shares memory with another argument and must
make a preventative copy of itself in order to maintain consistent semantics,
but `copy(A)` returns a new array of type `Array{CartesianIndex{2},2}`. To fix, implement:
    `Base.unaliascopy(A::CartesianIndices)::typeof(A)`

```

Is this a bug or intended behavior? The error only occurs when `index1==index2` so when the full view is accessed. Note also that this is an MWE, I know that in this case I could simply do `a[:]=rand(2,2)` which works, but in my case the indices are computed and may or may not span over the full array.

I just realized that `a[index2.indices...]` actually works, does this have any performance implications?
