parent
cbeefc877c
commit
28bed059aa
1 changed files with 35 additions and 0 deletions
35
tests/effects/tfuncs_cannot_mutate3.nim
Normal file
35
tests/effects/tfuncs_cannot_mutate3.nim
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue