writing to a location counts as "side effect"; implements https://github.com/nim-lang/RFCs/issues/234 (#15030)

This commit is contained in:
Andreas Rumpf
2020-07-25 15:14:28 +02:00
committed by GitHub
parent 1330597f6d
commit 7ca32c86bb
5 changed files with 283 additions and 5 deletions

View File

@@ -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"