discard destroys its argument in-place (#9478)

This commit is contained in:
LemonBoy 2019-02-23 14:03:32 +01:00 • committed by Andreas Rumpf
commit f39aa1b40b
2 changed files with 22 additions and 0 deletions

View file

@ -601,6 +601,10 @@ proc p(n: PNode; c: var Con): PNode =
of nkNone..nkNilLit, nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef,
nkIteratorDef, nkMacroDef, nkTemplateDef, nkLambda, nkDo, nkFuncDef:
result = n
of nkDiscardStmt:
result = n
if n[0].typ != nil and hasDestructor(n[0].typ):
result = genDestroy(c, n[0].typ, n[0])
of nkCast, nkHiddenStdConv, nkHiddenSubConv, nkConv:
result = copyNode(n)
# Destination type