fixes #5055
This commit is contained in:
parent
7b44896e03
commit
8494338bcb
4 changed files with 20 additions and 7 deletions
|
|
@ -1129,11 +1129,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
|
||||||
|
|
||||||
proc genConstExpr(p: BProc, n: PNode): Rope
|
proc genConstExpr(p: BProc, n: PNode): Rope
|
||||||
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
||||||
proc forbiddenType(t: PType): bool {.inline.} =
|
if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr:
|
||||||
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):
|
|
||||||
var t = getUniqueType(n.typ)
|
var t = getUniqueType(n.typ)
|
||||||
discard getTypeDesc(p.module, t) # so that any fields are initialized
|
discard getTypeDesc(p.module, t) # so that any fields are initialized
|
||||||
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
|
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 =
|
proc genConstSimpleList(p: BProc, n: PNode): Rope =
|
||||||
var length = sonsLen(n)
|
var length = sonsLen(n)
|
||||||
result = rope("{")
|
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):
|
for i in countup(ord(n.kind == nkObjConstr), length - 2):
|
||||||
addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])])
|
addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])])
|
||||||
if length > ord(n.kind == nkObjConstr):
|
if length > ord(n.kind == nkObjConstr):
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ const
|
||||||
cfsFieldInfo: "NIM_merge_FIELD_INFO",
|
cfsFieldInfo: "NIM_merge_FIELD_INFO",
|
||||||
cfsTypeInfo: "NIM_merge_TYPE_INFO",
|
cfsTypeInfo: "NIM_merge_TYPE_INFO",
|
||||||
cfsProcHeaders: "NIM_merge_PROC_HEADERS",
|
cfsProcHeaders: "NIM_merge_PROC_HEADERS",
|
||||||
cfsData: "NIM_merge_DATA",
|
|
||||||
cfsVars: "NIM_merge_VARS",
|
cfsVars: "NIM_merge_VARS",
|
||||||
|
cfsData: "NIM_merge_DATA",
|
||||||
cfsProcs: "NIM_merge_PROCS",
|
cfsProcs: "NIM_merge_PROCS",
|
||||||
cfsInitProc: "NIM_merge_INIT_PROC",
|
cfsInitProc: "NIM_merge_INIT_PROC",
|
||||||
cfsTypeInit1: "NIM_merge_TYPE_INIT1",
|
cfsTypeInit1: "NIM_merge_TYPE_INIT1",
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ type
|
||||||
cfsFieldInfo, # section for field information
|
cfsFieldInfo, # section for field information
|
||||||
cfsTypeInfo, # section for type information
|
cfsTypeInfo, # section for type information
|
||||||
cfsProcHeaders, # section for C procs prototypes
|
cfsProcHeaders, # section for C procs prototypes
|
||||||
cfsData, # section for C constant data
|
|
||||||
cfsVars, # section for C variable declarations
|
cfsVars, # section for C variable declarations
|
||||||
|
cfsData, # section for C constant data
|
||||||
cfsProcs, # section for C procs that are not inline
|
cfsProcs, # section for C procs that are not inline
|
||||||
cfsInitProc, # section for the C init proc
|
cfsInitProc, # section for the C init proc
|
||||||
cfsTypeInit1, # section 1 for declarations of type information
|
cfsTypeInit1, # section 1 for declarations of type information
|
||||||
|
|
|
||||||
14
tests/ccgbugs/tobjconstr_regression.nim
Normal file
14
tests/ccgbugs/tobjconstr_regression.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue