diff --git a/lib/system/assign.nim b/lib/system/assign.nim index d1055fbb50..59c44a6cce 100755 --- a/lib/system/assign.nim +++ b/lib/system/assign.nim @@ -7,6 +7,8 @@ # distribution, for details about the copyright. # +proc genericResetAux(dest: Pointer, n: ptr TNimNode) + proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) proc genericAssignAux(dest, src: Pointer, n: ptr TNimNode, shallow: bool) = var @@ -20,10 +22,16 @@ proc genericAssignAux(dest, src: Pointer, n: ptr TNimNode, shallow: bool) = for i in 0..n.len-1: genericAssignAux(dest, src, n.sons[i], shallow) of nkCase: + var dd = selectBranch(dest, n) + var m = selectBranch(src, n) + # reset if different branches are in use; note different branches also + # imply that's not self-assignment (``x = x``)! + if m != dd and dd != nil: + genericResetAux(dest, dd) copyMem(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset), n.typ.size) - var m = selectBranch(src, n) - if m != nil: genericAssignAux(dest, src, m, shallow) + if m != nil: + genericAssignAux(dest, src, m, shallow) of nkNone: sysAssert(false, "genericAssignAux") #else: # echo "ugh memory corruption! ", n.kind diff --git a/todo.txt b/todo.txt index 5a71d15af5..87f75c0d57 100755 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,6 @@ version 0.9.0 ============= -- bug: generic assign still buggy - - special case the generic assign that needs to care about case objects - make templates hygienic by default - ``bind`` for overloaded symbols does not work apparently - ``=`` should be overloadable; requires specialization for ``=``