tfuncs_cannot_mutate2.nim 578 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. errormsg: "'copy' can have side effects"
  3. nimout: '''an object reachable from 'y' is potentially mutated
  4. tfuncs_cannot_mutate2.nim(15, 7) the mutation is here
  5. tfuncs_cannot_mutate2.nim(13, 10) is the statement that connected the mutation to the parameter
  6. '''
  7. """
  8. {.experimental: "strictFuncs".}
  9. func copy[T](x: var openArray[T]; y: openArray[T]) =
  10. for i in 0..high(x):
  11. x[i] = y[i]
  12. x[0].a = nil
  13. type
  14. R = ref object
  15. a, b: R
  16. data: string
  17. proc main =
  18. var a, b: array[3, R]
  19. b = [R(data: "a"), R(data: "b"), R(data: "c")]
  20. copy a, b
  21. main()