diff options
author | cooldome <ariabushenko@gmail.com> | 2020-09-16 16:26:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 17:26:45 +0200 |
commit | a3e9cc52343a54cadc7b77b783e1c8b6ba2b327f (patch) | |
tree | 53b08cbbc176a3ae27ddbb35a6cbe9521a7ba104 /tests | |
parent | ae4ede6b009632bd0d809c61066b240e8ee7719a (diff) | |
download | Nim-a3e9cc52343a54cadc7b77b783e1c8b6ba2b327f.tar.gz |
Introduce explicit copy (#15330)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arc/tcopytosink_warning.nim | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/arc/tcopytosink_warning.nim b/tests/arc/tcopytosink_warning.nim new file mode 100644 index 000000000..8ae36386a --- /dev/null +++ b/tests/arc/tcopytosink_warning.nim @@ -0,0 +1,22 @@ +discard """ + cmd: "nim c --gc:arc $file" + nimout: '''tcopytosink_warning.nim(17, 7) Hint: myhint [User] +tcopytosink_warning.nim(19, 9) Hint: passing 'x' to a sink parameter introduces an implicit copy; if possible, rearrange your program's control flow to prevent it or use 'copy(x)' to hint the compiler it is intentional [Performance] +''' + output: "x" +""" +import macros + +proc test(v: var seq[string], x: sink string) = + v.add x + +var v = @["a", "b", "c"] +var x = "x" + +static: + hint("myhint") +test(v, copy(x)) # no warning +test(v, x) # produces warning + +echo x # use after sink + |