fixes a long standing bug concerning assignment of case objects

This commit is contained in:
Araq
2012-05-22 01:02:33 +02:00
parent ea5b74c832
commit 7f64e95747
2 changed files with 10 additions and 4 deletions

View File

@@ -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

View File

@@ -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 ``=``