From b2898cd25497cf80dc01587540da9903201c6b50 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 7 Apr 2019 23:11:37 +0200 Subject: [PATCH] an owned ref parameter behaves as a 'sink' parameter --- compiler/ast.nim | 6 ++++++ compiler/injectdestructors.nim | 13 +++++-------- compiler/liftdestructors.nim | 3 --- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 1f10328d5a..75e67ac679 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1812,6 +1812,12 @@ template detailedInfo*(sym: PSym): string = proc isInlineIterator*(s: PSym): bool {.inline.} = s.kind == skIterator and s.typ.callConv != ccClosure +proc isSinkParam*(s: PSym): bool {.inline.} = + s.kind == skParam and (s.typ.kind == tySink or tfHasOwned in s.typ.flags) + +proc isSinkType*(t: PType): bool {.inline.} = + t.kind == tySink or tfHasOwned in t.flags + proc newProcType*(info: TLineInfo; owner: PSym): PType = result = newType(tyProc, owner) result.n = newNodeI(nkFormalParams, info) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 350fd9c8d2..d4f7369afe 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -315,7 +315,7 @@ proc checkForErrorPragma(c: Con; t: PType; ri: PNode; opname: string) = if c.otherRead != nil: m.add "; another read is done here: " m.add c.graph.config $ c.otherRead.info - elif ri.kind == nkSym and ri.sym.kind == skParam and ri.sym.typ.kind != tySink: + elif ri.kind == nkSym and ri.sym.kind == skParam and not isSinkType(ri.sym.typ): m.add "; try to make " m.add renderTree(ri) m.add " a 'sink' parameter" @@ -381,9 +381,6 @@ template recurse(n, dest) = for i in 0..