diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/destructor/tdestructor3.nim | 3 | ||||
-rw-r--r-- | tests/destructor/tmatrix.nim | 13 | ||||
-rw-r--r-- | tests/destructor/topttree.nim | 3 | ||||
-rw-r--r-- | tests/destructor/tprevent_assign2.nim | 48 |
4 files changed, 65 insertions, 2 deletions
diff --git a/tests/destructor/tdestructor3.nim b/tests/destructor/tdestructor3.nim index 3e177d3cd..5756e9afb 100644 --- a/tests/destructor/tdestructor3.nim +++ b/tests/destructor/tdestructor3.nim @@ -19,9 +19,12 @@ proc `=`(lhs: var T, rhs: T) = proc `=destroy`(v: var T) = echo "destroy" +proc use(x: T) = discard + proc usedToBeBlock = var v1 : T var v2 : T = v1 + use v1 usedToBeBlock() diff --git a/tests/destructor/tmatrix.nim b/tests/destructor/tmatrix.nim index ba08ec4d6..a16bfa37b 100644 --- a/tests/destructor/tmatrix.nim +++ b/tests/destructor/tmatrix.nim @@ -1,6 +1,7 @@ discard """ - output: '''after 3 3 -after 3 3 + output: '''after 2 2 +after 2 2 +after 2 2 after 2 2''' """ # bug #9263 @@ -107,6 +108,11 @@ proc test3 = # a = a - b b = -b + a +proc test4 = + # bug #9294 + var a = matrix(5, 5, 1.0) + a = -a + a + test1() info() @@ -115,3 +121,6 @@ info() test3() info() + +test4() +info() diff --git a/tests/destructor/topttree.nim b/tests/destructor/topttree.nim index 924644392..21b283be0 100644 --- a/tests/destructor/topttree.nim +++ b/tests/destructor/topttree.nim @@ -90,6 +90,8 @@ proc write(t: opt[Tree]) = write stdout, it.data, "\n" write(it.ri) +proc use(t: opt[Tree]) = discard + proc main = var t: opt[Tree] insert t, 60.0 @@ -99,6 +101,7 @@ proc main = write t let copy = t write copy + use t main() echo allocCount, " ", deallocCount diff --git a/tests/destructor/tprevent_assign2.nim b/tests/destructor/tprevent_assign2.nim new file mode 100644 index 000000000..4ef62d2fd --- /dev/null +++ b/tests/destructor/tprevent_assign2.nim @@ -0,0 +1,48 @@ +discard """ + errormsg: "'=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" + line: 44 +""" + +type + Foo = object + x: int + +proc `=destroy`(f: var Foo) = f.x = 0 +proc `=`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=sink`(a: var Foo; b: Foo) = a.x = b.x + +proc createTree(x: int): Foo = + Foo(x: x) + +proc take2(a, b: sink Foo) = + echo a.x, " ", b.x + +proc allowThis() = + var otherTree: Foo + for i in 0..3: + while true: + #if i == 0: + otherTree = createTree(44) + case i + of 0: + echo otherTree + take2(createTree(34), otherTree) + of 1: + take2(createTree(34), otherTree) + else: + discard + +proc preventThis() = + var otherTree: Foo + for i in 0..3: + while true: + if i == 0: + otherTree = createTree(44) + case i + of 0: + echo otherTree + take2(createTree(34), otherTree) + of 1: + take2(createTree(34), otherTree) + else: + discard |