diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-09-27 15:36:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 09:36:09 +0200 |
commit | d4027f25c4af0b892614ef9237c1318085516e07 (patch) | |
tree | 3f086c07868faedcf236cc51f917c5204b21716a /tests | |
parent | 75b9d665822d87d90372f6a5a3ffded96887e3db (diff) | |
download | Nim-d4027f25c4af0b892614ef9237c1318085516e07.tar.gz |
fixes #24175; Sink parameters not copied at compile time (#24178)
fixes #24175
Diffstat (limited to 'tests')
-rw-r--r-- | tests/destructor/tsink.nim | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/destructor/tsink.nim b/tests/destructor/tsink.nim index e214e4cca..e8750ad7c 100644 --- a/tests/destructor/tsink.nim +++ b/tests/destructor/tsink.nim @@ -22,3 +22,49 @@ block: # bug #23902 proc foo(a: sink string) = var x = (a, a) + +block: # bug #24175 + block: + func mutate(o: sink string): string = + o[1] = '1' + result = o + + static: + let s = "999" + let m = mutate(s) + doAssert s == "999" + doAssert m == "919" + + func foo() = + let s = "999" + let m = mutate(s) + doAssert s == "999" + doAssert m == "919" + + static: + foo() + foo() + + block: + type O = object + a: int + + func mutate(o: sink O): O = + o.a += 1 + o + + static: + let x = O(a: 1) + let y = mutate(x) + doAssert x.a == 1 + doAssert y.a == 2 + + proc foo() = + let x = O(a: 1) + let y = mutate(x) + doAssert x.a == 1 + doAssert y.a == 2 + + static: + foo() + foo() |