This commit is contained in:
Araq 2019-08-12 14:06:48 +02:00
commit 322ce1872f
2 changed files with 22 additions and 1 deletions

View file

@ -796,6 +796,10 @@ proc p(n: PNode; c: var Con): PNode =
result = n result = n
of nkAsgn, nkFastAsgn: of nkAsgn, nkFastAsgn:
if hasDestructor(n[0].typ) and n[1].kind notin {nkProcDef, nkDo, nkLambda}: if hasDestructor(n[0].typ) and n[1].kind notin {nkProcDef, nkDo, nkLambda}:
# rule (self-assignment-removal):
if n[1].kind == nkSym and n[0].kind == nkSym and n[0].sym == n[1].sym:
result = newNodeI(nkEmpty, n.info)
else:
result = moveOrCopy(n[0], n[1], c) result = moveOrCopy(n[0], n[1], c)
else: else:
result = copyNode(n) result = copyNode(n)

View file

@ -3,6 +3,7 @@ discard """
output: '''(field: "value") output: '''(field: "value")
Indeed Indeed
axc axc
(v: 10)
0 new: 0''' 0 new: 0'''
""" """
@ -58,5 +59,21 @@ proc test(p: owned proc()) =
test(proc() = discard) test(proc() = discard)
# bug #10689
type
O = object
v: int
proc `=sink`(d: var O, s: O) =
d.v = s.v
proc selfAssign =
var o = O(v: 10)
o = o
echo o
selfAssign()
let (a, d) = allocCounters() let (a, d) = allocCounters()
discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs) discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs)