diff options
Diffstat (limited to 'tests/effects/tfuncs_cannot_mutate.nim')
-rw-r--r-- | tests/effects/tfuncs_cannot_mutate.nim | 35 |
1 files changed, 35 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..9934d27a7 --- /dev/null +++ b/tests/effects/tfuncs_cannot_mutate.nim @@ -0,0 +1,35 @@ +discard """ + errormsg: "cannot mutate location select(x, z).data within a strict func" + line: 35 +""" + +{.experimental: "strictFuncs".} + +type + Node = ref object + le, ri: Node + data: string + +func insert(x: var seq[Node]; yyy: Node) = + let L = x.len + x.setLen L + 1 + x[L] = yyy + +func len(n: Node): int = + var it = n + while it != nil: + inc result + it = it.ri + +func doNotDistract(n: Node) = + var m = Node(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" |