Introduce explicit copy (#15330)

This commit is contained in:
cooldome 2020-09-16 16:26:45 +01:00 • committed by GitHub
commit a3e9cc5234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

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