reject_copy_into_subslice.mx raw

   1  // expected: a subslice is a copy, so copying into it is not allowed
   2  //
   3  // copy's destination is a write, and a subslice is a copy, so copy(x[a:b], src)
   4  // fills a throwaway that occupies arena space and leaves x untouched. The same
   5  // rule as an assignment through a subslice; the fix is to write the elements or
   6  // resize the slice. copy(x[1], src) is addressing an element, not subslicing,
   7  // and is untouched by this rule.
   8  package main
   9  
  10  func main() {
  11  	xs := []byte{1, 2, 3, 4}
  12  	copy(xs[1:3], []byte{9, 9})
  13  	println(xs[1])
  14  }
  15