parent
d1bea1f71f
commit
fa5f225efc
2 changed files with 42 additions and 10 deletions
|
|
@ -824,10 +824,6 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode): PNode =
|
||||||
of nkAsgn, nkFastAsgn:
|
of nkAsgn, nkFastAsgn:
|
||||||
if hasDestructor(c, n[0].typ) and n[1].kind notin {nkProcDef, nkDo, nkLambda} and
|
if hasDestructor(c, n[0].typ) and n[1].kind notin {nkProcDef, nkDo, nkLambda} and
|
||||||
not isCursor(n[0], c):
|
not isCursor(n[0], c):
|
||||||
# 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:
|
|
||||||
if n[0].kind in {nkDotExpr, nkCheckedFieldExpr}:
|
if n[0].kind in {nkDotExpr, nkCheckedFieldExpr}:
|
||||||
cycleCheck(n, c)
|
cycleCheck(n, c)
|
||||||
assert n[1].kind notin {nkAsgn, nkFastAsgn}
|
assert n[1].kind notin {nkAsgn, nkFastAsgn}
|
||||||
|
|
@ -955,7 +951,10 @@ proc moveOrCopy(dest, ri: PNode; c: var Con; s: var Scope, isDecl = false): PNod
|
||||||
of nkObjConstr, nkTupleConstr, nkClosure, nkCharLit..nkNilLit:
|
of nkObjConstr, nkTupleConstr, nkClosure, nkCharLit..nkNilLit:
|
||||||
result = c.genSink(dest, p(ri, c, s, consumed), isDecl)
|
result = c.genSink(dest, p(ri, c, s, consumed), isDecl)
|
||||||
of nkSym:
|
of nkSym:
|
||||||
if isSinkParam(ri.sym) and isLastRead(ri, c):
|
if dest.kind == nkSym and dest.sym == ri.sym:
|
||||||
|
# rule (self-assignment-removal):
|
||||||
|
result = newNodeI(nkEmpty, dest.info)
|
||||||
|
elif isSinkParam(ri.sym) and isLastRead(ri, c):
|
||||||
# Rule 3: `=sink`(x, z); wasMoved(z)
|
# Rule 3: `=sink`(x, z); wasMoved(z)
|
||||||
let snk = c.genSink(dest, ri, isDecl)
|
let snk = c.genSink(dest, ri, isDecl)
|
||||||
result = newTree(nkStmtList, snk, c.genWasMoved(ri))
|
result = newTree(nkStmtList, snk, c.genWasMoved(ri))
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ king
|
||||||
hi
|
hi
|
||||||
try
|
try
|
||||||
bye
|
bye
|
||||||
|
()
|
||||||
|
()
|
||||||
|
()
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -524,3 +527,33 @@ proc getScope2(): string =
|
||||||
"else"
|
"else"
|
||||||
|
|
||||||
echo getScope2()
|
echo getScope2()
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------
|
||||||
|
#bug #15609
|
||||||
|
|
||||||
|
type
|
||||||
|
Wrapper = object
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc newWrapper(): ref Wrapper =
|
||||||
|
new(result)
|
||||||
|
result
|
||||||
|
|
||||||
|
|
||||||
|
proc newWrapper2(a: int): ref Wrapper =
|
||||||
|
new(result)
|
||||||
|
if a > 0:
|
||||||
|
result
|
||||||
|
else:
|
||||||
|
new(Wrapper)
|
||||||
|
|
||||||
|
|
||||||
|
let w1 = newWrapper()
|
||||||
|
echo $w1[]
|
||||||
|
|
||||||
|
let w2 = newWrapper2(1)
|
||||||
|
echo $w2[]
|
||||||
|
|
||||||
|
let w3 = newWrapper2(-1)
|
||||||
|
echo $w3[]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue