Skip to content

Commit

Permalink
fixes #5402
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Feb 16, 2017
1 parent 71026ce commit 6499462
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
optAsgnLoc(src, t, field), newflags)

proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags,
t: PNode) =
t: PNode, typ: PType) =
if t == nil: return
let newflags =
if src.s == OnStatic:
Expand All @@ -232,10 +232,11 @@ proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags,
case t.kind
of nkSym:
let field = t.sym
if field.loc.r == nil: fillObjectFields(p.module, typ)
genAssignment(p, optAsgnLoc(dest, field.typ, field.loc.r),
optAsgnLoc(src, field.typ, field.loc.r), newflags)
of nkRecList:
for child in items(t): genOptAsgnObject(p, dest, src, newflags, child)
for child in items(t): genOptAsgnObject(p, dest, src, newflags, child, typ)
else: discard

proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
Expand Down Expand Up @@ -315,9 +316,9 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
genGenericAsgn(p, dest, src, flags)
elif needsComplexAssignment(ty):
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
discard getTypeDesc(p.module, dest.t)
discard getTypeDesc(p.module, ty)
internalAssert ty.n != nil
genOptAsgnObject(p, dest, src, flags, ty.n)
genOptAsgnObject(p, dest, src, flags, ty.n, ty)
else:
genGenericAsgn(p, dest, src, flags)
else:
Expand Down
26 changes: 26 additions & 0 deletions tests/ccgbugs/tgeneric_smallobj_asgn_opt.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
discard """
output: '''false'''
"""

# bug #5402

import lists

type
Container[T] = ref object
obj: T

ListOfContainers[T] = ref object
list: DoublyLinkedList[Container[T]]

proc contains[T](this: ListOfContainers[T], obj: T): bool =
for item in this.list.items():
if item.obj == obj: return true
return false

proc newListOfContainers[T](): ListOfContainers[T] =
new(result)
result.list = initDoublyLinkedList[Container[T]]()

let q = newListOfContainers[int64]()
echo q.contains(123)

0 comments on commit 6499462

Please sign in to comment.