summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/destructor/t6434.nim4
-rw-r--r--tests/destructor/tmatrix.nim4
-rw-r--r--tests/destructor/tobjfield_analysis.nim35
3 files changed, 39 insertions, 4 deletions
diff --git a/tests/destructor/t6434.nim b/tests/destructor/t6434.nim
index 5f5fbedfa..4e78d0469 100644
--- a/tests/destructor/t6434.nim
+++ b/tests/destructor/t6434.nim
@@ -23,5 +23,5 @@ proc test(): auto =
 
 var (a, b, _) = test()
 
-doAssert: assign_counter == 0
-doAssert: sink_counter == 9
\ No newline at end of file
+doAssert assign_counter == 0
+doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation
diff --git a/tests/destructor/tmatrix.nim b/tests/destructor/tmatrix.nim
index b89b41a4c..a3bd59df3 100644
--- a/tests/destructor/tmatrix.nim
+++ b/tests/destructor/tmatrix.nim
@@ -88,8 +88,8 @@ proc `-`*(a: sink Matrix; b: Matrix): Matrix =
   doAssert(a.len == b.len) # non destructive use before sink is ok
   result = a
   for i in 0 ..< result.m:
-     for j in 0 ..< result.n:
-        result[i, j] = a[i, j] - b[i, j]
+    for j in 0 ..< result.n:
+      result[i, j] = a[i, j] - b[i, j]
 
 proc info =
   echo "after ", allocCount, " ", deallocCount
diff --git a/tests/destructor/tobjfield_analysis.nim b/tests/destructor/tobjfield_analysis.nim
new file mode 100644
index 000000000..24cf02aee
--- /dev/null
+++ b/tests/destructor/tobjfield_analysis.nim
@@ -0,0 +1,35 @@
+discard """
+  output: '''works'''
+"""
+
+type
+  MyVal = object
+    f: ptr float
+
+proc `=destroy`(x: var MyVal) =
+  if x.f != nil:
+    dealloc(x.f)
+
+proc `=sink`(x1: var MyVal, x2: Myval) =
+  if x1.f != x2.f:
+    `=destroy`(x1)
+    x1.f = x2.f
+
+proc `=`(x1: var MyVal, x2: Myval) {.error.}
+
+proc newVal(x: float): MyVal =
+  result.f = create(float)
+  result.f[] = x
+
+proc sinkMe(x: sink MyVal) =
+  discard
+
+proc main =
+  var y = (newVal(3.0), newVal(4.0))
+
+  sinkMe y[0]
+  sinkMe y[1]
+  echo "works"
+
+main()
+