tfuncs_cannot_mutate2.nim 392 B

12345678910111213141516171819202122232425
  1. discard """
  2. errormsg: "cannot mutate location x[0].a within a strict func"
  3. line: 12
  4. """
  5. {.experimental: "strictFuncs".}
  6. func copy[T](x: var openArray[T]; y: openArray[T]) =
  7. for i in 0..high(x):
  8. x[i] = y[i]
  9. x[0].a = nil
  10. type
  11. R = ref object
  12. a, b: R
  13. data: string
  14. proc main =
  15. var a, b: array[3, R]
  16. b = [R(data: "a"), R(data: "b"), R(data: "c")]
  17. copy a, b
  18. main()