summary refs log tree commit diff stats
path: root/tests/effects
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2022-12-12 11:46:51 +0100
committerGitHub <noreply@github.com>2022-12-12 11:46:51 +0100
commit28bed059aadf808fe56eaf2b36274bdf6baec053 (patch)
tree7fa795ef7f187c61d15954f87e1f179c8e235137 /tests/effects
parentcbeefc877cd752cd2e19a82fe3aa2914912f3182 (diff)
downloadNim-28bed059aadf808fe56eaf2b36274bdf6baec053.tar.gz
closes #20808 (#21077)
Diffstat (limited to 'tests/effects')
-rw-r--r--tests/effects/tfuncs_cannot_mutate3.nim35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/effects/tfuncs_cannot_mutate3.nim b/tests/effects/tfuncs_cannot_mutate3.nim
new file mode 100644
index 000000000..029152029
--- /dev/null
+++ b/tests/effects/tfuncs_cannot_mutate3.nim
@@ -0,0 +1,35 @@
+discard """
+  errormsg: "cannot mutate location kid.parent within a strict func"
+  line: 16
+"""
+
+{.experimental: "strictFuncs".}
+
+type
+  Node = ref object
+    name: string
+    kids: seq[Node]
+    parent: Node
+
+func initParents(tree: Node) =
+  for kid in tree.kids:
+    kid.parent = tree
+    initParents(kid)
+
+proc process(intro: Node): Node =
+  var tree = Node(name: "root", kids: @[
+    intro,
+    Node(name: "one", kids: @[
+      Node(name: "two"),
+      Node(name: "three"),
+    ]),
+    Node(name: "four"),
+  ])
+  initParents(tree)
+
+proc main() =
+  var intro = Node(name: "intro")
+  var tree = process(intro)
+  echo intro.parent.name
+
+main()