summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/liftdestructors.nim7
-rw-r--r--tests/destructor/tarc.nim26
2 files changed, 31 insertions, 2 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim
index 6f4e5828d..d70b968a8 100644
--- a/compiler/liftdestructors.nim
+++ b/compiler/liftdestructors.nim
@@ -448,7 +448,8 @@ proc useSeqOrStrOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
 
   case c.kind
   of attachedAsgn, attachedDeepCopy:
-    doAssert t.assignment != nil
+    if t.assignment == nil:
+      return # protect from recursion
     body.add newHookCall(c.g, t.assignment, x, y)
   of attachedSink:
     # we always inline the move for better performance:
@@ -465,8 +466,12 @@ proc useSeqOrStrOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
     doAssert t.destructor != nil
     body.add destructorCall(c, t.destructor, x)
   of attachedTrace:
+    if t.attachedOps[c.kind] == nil:
+      return # protect from recursion
     body.add newHookCall(c.g, t.attachedOps[c.kind], x, y)
   of attachedDispose:
+    if t.attachedOps[c.kind] == nil:
+      return # protect from recursion
     body.add newHookCall(c.g, t.attachedOps[c.kind], x, nil)
 
 proc fillStrOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
diff --git a/tests/destructor/tarc.nim b/tests/destructor/tarc.nim
index 1acc95fad..12ea46b2c 100644
--- a/tests/destructor/tarc.nim
+++ b/tests/destructor/tarc.nim
@@ -6,7 +6,9 @@ Success
 Hello
 1
 2
-0'''
+0
+List
+'''
   cmd: '''nim c --gc:arc $file'''
 """
 
@@ -145,3 +147,25 @@ proc bug13105 =
 bug13105()
 
 echo getOccupiedMem() - startMem
+
+
+#------------------------------------------------------------------------------
+# issue #14294
+
+import tables
+
+type
+  TagKind = enum
+    List = 0, Compound
+
+  Tag = object
+    case kind: TagKind
+    of List:
+      values: seq[Tag]
+    of Compound: 
+      compound: Table[string, Tag]
+
+var a = Tag(kind: List)
+var b = a
+echo a.kind
+var c = a