summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ccgexprs.nim5
-rw-r--r--tests/compile/tobjconstr2.nim8
2 files changed, 12 insertions, 1 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index a99654cbd..426f1b813 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1088,7 +1088,10 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
     tmp2.s = onHeap
     tmp2.heapRoot = tmp.r
     expr(p, it.sons[1], tmp2)
-  genAssignment(p, d, tmp, {})
+  if d.k == locNone:
+    d = tmp
+  else:
+    genAssignment(p, d, tmp, {})
   
 proc genSeqConstr(p: BProc, t: PNode, d: var TLoc) =
   var arr: TLoc
diff --git a/tests/compile/tobjconstr2.nim b/tests/compile/tobjconstr2.nim
new file mode 100644
index 000000000..ef5446999
--- /dev/null
+++ b/tests/compile/tobjconstr2.nim
@@ -0,0 +1,8 @@
+type TFoo{.exportc.} = object
+ x:int
+
+var s{.exportc.}: seq[TFoo] = @[]
+
+s.add TFoo(x: 42)
+
+echo s[0].x