From 7435d912adcf411feed4ba124808527c7e04a44f Mon Sep 17 00:00:00 2001 From: Clyybber Date: Thu, 22 Oct 2020 13:23:39 +0200 Subject: Add testcase for #14601 (#15677) --- tests/destructor/tdestructor3.nim | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'tests/destructor/tdestructor3.nim') diff --git a/tests/destructor/tdestructor3.nim b/tests/destructor/tdestructor3.nim index ca9a891e1..eb49f3f15 100644 --- a/tests/destructor/tdestructor3.nim +++ b/tests/destructor/tdestructor3.nim @@ -127,4 +127,48 @@ proc test2() = echo "---------------" echo "app begin" test2() -echo "app end" \ No newline at end of file +echo "app end" + +# bug #14601 + +when true: # D20200607T202043 + type Foo2 = object + x: int + x2: array[10, int] + + type Vec = object + vals: seq[Foo2] + + proc `=destroy`*(a: var Foo2) {.inline.} = + discard + + proc initFoo2(x: int): Foo2 = Foo2(x: x) + + proc add2(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2` + v.vals.add a + + proc add3(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2` + v.vals = @[a] + + proc add4(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2` + v.vals.add a + + proc add5(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2` + v.vals = @[a] + + proc main2()= + var a: Vec + var b = Foo2(x: 10) + a.add2 b # ok + a.vals.add Foo2(x: 10) # ok + a.add2 initFoo2(x = 10) # ok + a.add2 Foo2(x: 10) # bug + a.add3 initFoo2(x = 10) # ok + a.add3 Foo2(x: 10) # bug + a.add4 initFoo2(x = 10) # ok + a.add4 Foo2(x: 10) # bug + a.add5 initFoo2(x = 10) # ok + a.add5 Foo2(x: 10) # bug + main2() + + -- cgit 1.4.1-2-gfad0 f/tests/trmacros/tnorewrite.nim?h=devel&id=827971dab2a455559d9df7c79efb882a273203d0'>diff stats
path: root/tests/trmacros/tnorewrite.nim
blob: e6769246f5fc049889078b6da898ba606518f5f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20