tfuncs_cannot_mutate.nim 755 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. errormsg: "'mutate' can have side effects"
  3. nimout: '''an object reachable from 'n' is potentially mutated
  4. tfuncs_cannot_mutate.nim(39, 15) the mutation is here
  5. tfuncs_cannot_mutate.nim(37, 7) is the statement that connected the mutation to the parameter
  6. '''
  7. """
  8. {.experimental: "strictFuncs".}
  9. type
  10. Node = ref object
  11. le, ri: Node
  12. data: string
  13. func insert(x: var seq[Node]; yyy: Node) =
  14. let L = x.len
  15. x.setLen L + 1
  16. x[L] = yyy
  17. func len(n: Node): int =
  18. var it = n
  19. while it != nil:
  20. inc result
  21. it = it.ri
  22. func doNotDistract(n: Node) =
  23. var m = Node()
  24. m.data = "abc"
  25. func select(a, b: Node): Node = b
  26. func mutate(n: Node) =
  27. var it = n
  28. let x = it
  29. let y = x
  30. let z = y
  31. select(x, z).data = "tricky"