summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-07-25 15:14:28 +0200
committerGitHub <noreply@github.com>2020-07-25 15:14:28 +0200
commit7ca32c86bbb84ac7bcadd0a2bc2cd5fc277f1bff (patch)
tree1bce8429d7d592ae8115aa13699c58d6a5605fe1 /tests
parent1330597f6df1d2f7d23ec25a7705e21be2e78d29 (diff)
downloadNim-7ca32c86bbb84ac7bcadd0a2bc2cd5fc277f1bff.tar.gz
writing to a location counts as "side effect"; implements https://github.com/nim-lang/RFCs/issues/234 (#15030)
Diffstat (limited to 'tests')
-rw-r--r--tests/effects/tfuncs_cannot_mutate.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/effects/tfuncs_cannot_mutate.nim b/tests/effects/tfuncs_cannot_mutate.nim
new file mode 100644
index 000000000..ec3ad43f7
--- /dev/null
+++ b/tests/effects/tfuncs_cannot_mutate.nim
@@ -0,0 +1,31 @@
+discard """
+  errormsg: "'mutate' can have side effects"
+  line: 25
+"""
+
+{.experimental: "strictFuncs".}
+
+type
+  Node = ref object
+    le, ri: Node
+    data: string
+
+func len(n: Node): int =
+  var it = n
+  while it != nil:
+    inc result
+    it = it.ri
+
+func doNotDistract(n: Node) =
+  var m = Node()
+  m.data = "abc"
+
+func select(a, b: Node): Node = b
+
+func mutate(n: Node) =
+  var it = n
+  let x = it
+  let y = x
+  let z = y
+
+  select(x, z).data = "tricky"