summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ccgexprs.nim9
-rw-r--r--compiler/ccgmerge.nim2
-rw-r--r--compiler/cgendata.nim2
-rw-r--r--tests/ccgbugs/tobjconstr_regression.nim14
4 files changed, 20 insertions, 7 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index b863568d3..feb70071a 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1129,11 +1129,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
 
 proc genConstExpr(p: BProc, n: PNode): Rope
 proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
-  proc forbiddenType(t: PType): bool {.inline.} =
-    result = t.kind == tyObject and not isObjLackingTypeField(t)
-    #echo "forbidden type ", result
-  if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr and
-      not forbiddenType(n.typ):
+  if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr:
     var t = getUniqueType(n.typ)
     discard getTypeDesc(p.module, t) # so that any fields are initialized
     let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
@@ -2156,6 +2152,9 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope =
 proc genConstSimpleList(p: BProc, n: PNode): Rope =
   var length = sonsLen(n)
   result = rope("{")
+  if n.kind == nkObjConstr and not isObjLackingTypeField(n.typ):
+    addf(result, "{$1}", [genTypeInfo(p.module, n.typ)])
+    if n.len > 1: add(result, ",")
   for i in countup(ord(n.kind == nkObjConstr), length - 2):
     addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])])
   if length > ord(n.kind == nkObjConstr):
diff --git a/compiler/ccgmerge.nim b/compiler/ccgmerge.nim
index 92b6aa9dc..67ffaf8b0 100644
--- a/compiler/ccgmerge.nim
+++ b/compiler/ccgmerge.nim
@@ -27,8 +27,8 @@ const
     cfsFieldInfo: "NIM_merge_FIELD_INFO",
     cfsTypeInfo: "NIM_merge_TYPE_INFO",
     cfsProcHeaders: "NIM_merge_PROC_HEADERS",
-    cfsData: "NIM_merge_DATA",
     cfsVars: "NIM_merge_VARS",
+    cfsData: "NIM_merge_DATA",
     cfsProcs: "NIM_merge_PROCS",
     cfsInitProc: "NIM_merge_INIT_PROC",
     cfsTypeInit1: "NIM_merge_TYPE_INIT1",
diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim
index faeea7afb..def0b4fee 100644
--- a/compiler/cgendata.nim
+++ b/compiler/cgendata.nim
@@ -27,8 +27,8 @@ type
     cfsFieldInfo,             # section for field information
     cfsTypeInfo,              # section for type information
     cfsProcHeaders,           # section for C procs prototypes
-    cfsData,                  # section for C constant data
     cfsVars,                  # section for C variable declarations
+    cfsData,                  # section for C constant data
     cfsProcs,                 # section for C procs that are not inline
     cfsInitProc,              # section for the C init proc
     cfsTypeInit1,             # section 1 for declarations of type information
diff --git a/tests/ccgbugs/tobjconstr_regression.nim b/tests/ccgbugs/tobjconstr_regression.nim
new file mode 100644
index 000000000..87d037894
--- /dev/null
+++ b/tests/ccgbugs/tobjconstr_regression.nim
@@ -0,0 +1,14 @@
+discard """
+  output: "@[(username: user, role: admin, description: desc, email_addr: email), (username: user, role: admin, description: desc, email_addr: email)]"
+"""
+
+type
+  User = object of RootObj
+    username, role, description, email_addr: string
+
+# bug 5055
+let us4 = @[
+  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
+  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
+]
+echo us4