tfuncs_cannot_mutate.nim 574 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. errormsg: "cannot mutate location select(x, z).data within a strict func"
  3. line: 35
  4. """
  5. {.experimental: "strictFuncs".}
  6. type
  7. Node = ref object
  8. le, ri: Node
  9. data: string
  10. func insert(x: var seq[Node]; yyy: Node) =
  11. let L = x.len
  12. x.setLen L + 1
  13. x[L] = yyy
  14. func len(n: Node): int =
  15. var it = n
  16. while it != nil:
  17. inc result
  18. it = it.ri
  19. func doNotDistract(n: Node) =
  20. var m = Node(data: "abc")
  21. func select(a, b: Node): Node = b
  22. func mutate(n: Node) =
  23. var it = n
  24. let x = it
  25. let y = x
  26. let z = y
  27. select(x, z).data = "tricky"