fixes #1547
This commit is contained in:
parent
c1930f1b6e
commit
7edf6fc1d2
3 changed files with 20 additions and 2 deletions
|
|
@ -1718,7 +1718,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
|
|
||||||
proc genConstExpr(p: BProc, n: PNode): PRope
|
proc genConstExpr(p: BProc, n: PNode): PRope
|
||||||
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
||||||
if (nfAllConst in n.flags) and (d.k == locNone) and (sonsLen(n) > 0):
|
if nfAllConst in n.flags and d.k == locNone and n.len > 0 and n.isDeepConstExpr:
|
||||||
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
|
||||||
var id = nodeTableTestOrSet(p.module.dataCache, n, gBackendId)
|
var id = nodeTableTestOrSet(p.module.dataCache, n, gBackendId)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,9 @@ proc isDeepConstExpr*(n: PNode): bool =
|
||||||
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure:
|
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure:
|
||||||
for i in 0 .. <n.len:
|
for i in 0 .. <n.len:
|
||||||
if not isDeepConstExpr(n.sons[i]): return false
|
if not isDeepConstExpr(n.sons[i]): return false
|
||||||
result = true
|
# XXX once constant objects are supported by the codegen this needs to be
|
||||||
|
# weakened:
|
||||||
|
result = n.typ.isNil or n.typ.skipTypes({tyGenericInst, tyDistinct}).kind != tyObject
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc flattenTreeAux(d, a: PNode, op: TMagic) =
|
proc flattenTreeAux(d, a: PNode, op: TMagic) =
|
||||||
|
|
|
||||||
16
tests/ccgbugs/tconstobj.nim
Normal file
16
tests/ccgbugs/tconstobj.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
output: '''(FirstName: James, LastName: Franco)'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #1547
|
||||||
|
import tables
|
||||||
|
|
||||||
|
type Person* = object
|
||||||
|
FirstName*: string
|
||||||
|
LastName*: string
|
||||||
|
|
||||||
|
let people = {
|
||||||
|
"001": Person(FirstName: "James", LastName: "Franco")
|
||||||
|
}.toTable()
|
||||||
|
|
||||||
|
echo people["001"]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue