diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2021-06-09 17:33:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-09 17:33:19 +0200 |
commit | 47acc80f4e05053d2653c7218434bc7fad880741 (patch) | |
tree | 7cee76f3d6f6675c1fa91b9aa7e9a0a67f365266 /tests/effects/tfuncs_cannot_mutate2.nim | |
parent | 51ab7ccec1ffa21cef67f1a75dea889653751cfc (diff) | |
download | Nim-47acc80f4e05053d2653c7218434bc7fad880741.tar.gz |
make strict funcs analysis smarter (#18219)
* make strict funcs analysis smarter: varParam[i] = v is different from varParam[i][] = v * added a test case * Update compiler/varpartitions.nim Co-authored-by: Clyybber <darkmine956@gmail.com>
Diffstat (limited to 'tests/effects/tfuncs_cannot_mutate2.nim')
-rw-r--r-- | tests/effects/tfuncs_cannot_mutate2.nim | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/effects/tfuncs_cannot_mutate2.nim b/tests/effects/tfuncs_cannot_mutate2.nim new file mode 100644 index 000000000..d5082e57b --- /dev/null +++ b/tests/effects/tfuncs_cannot_mutate2.nim @@ -0,0 +1,27 @@ +discard """ + errormsg: "'copy' can have side effects" + nimout: '''an object reachable from 'y' is potentially mutated +tfuncs_cannot_mutate2.nim(15, 7) the mutation is here +tfuncs_cannot_mutate2.nim(13, 10) is the statement that connected the mutation to the parameter +''' +""" + +{.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() |