summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/varpartitions.nim2
-rw-r--r--tests/arc/t18971.nim10
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim
index 8f422face..709d00fa0 100644
--- a/compiler/varpartitions.nim
+++ b/compiler/varpartitions.nim
@@ -479,7 +479,7 @@ proc destMightOwn(c: var Partitions; dest: var VarIndex; n: PNode) =
         # calls do construct, what we construct must be destroyed,
         # so dest cannot be a cursor:
         dest.flags.incl ownsData
-      elif n.typ.kind in {tyLent, tyVar}:
+      elif n.typ.kind in {tyLent, tyVar} and n.len > 1:
         # we know the result is derived from the first argument:
         var roots: seq[(PSym, int)]
         allRoots(n[1], roots, RootEscapes)
diff --git a/tests/arc/t18971.nim b/tests/arc/t18971.nim
new file mode 100644
index 000000000..9b587d956
--- /dev/null
+++ b/tests/arc/t18971.nim
@@ -0,0 +1,10 @@
+discard """
+  cmd: "nim c --gc:arc $file"
+"""
+
+type MyObj = ref object
+
+var o = MyObj()
+proc x: var MyObj = o
+
+var o2 = x()