summary refs log tree commit diff stats
path: root/tests/effects/tfuncs_cannot_mutate2.nim
blob: 86f8110171c8d737ec9a93e47dc507865ae7b344 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
discard """
  errormsg: "cannot mutate location x[0].a within a strict func"
  line: 12
"""

{.experimental: "strictFuncs".}

func copy[T](x: var openArray[T]; y: openArray[T]) =
  for i in 0..high(x):
    x[i] = y[i]

  x[0].a = nil

type
  R = ref object
    a, b: R
    data: string

proc main =
  var a, b: array[3, R]
  b = [R(data: "a"), R(data: "b"), R(data: "c")]
  copy a, b

main()