diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 5958d89aec..73ff0869c9 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -419,6 +419,15 @@ proc sinkParamIsLastReadCheck(c: var Con, s: PNode) = localError(c.graph.config, c.otherRead.info, "sink parameter `" & $s.sym.name.s & "` is already consumed at " & toFileLineCol(c. graph.config, s.info)) +proc isSinkTypeForParam(t: PType): bool = + # a parameter like 'seq[owned T]' must not be used only once, but its + # elements must, so we detect this case here: + if isSinkType(t): + if t.skipTypes({tyGenericInst, tyAlias}).kind in {tyArray, tyVarargs, tyOpenArray, tySequence}: + result = false + else: + result = true + proc passCopyToSink(n: PNode; c: var Con): PNode = result = newNodeIT(nkStmtListExpr, n.info, n.typ) let tmp = getTemp(c, n.typ, n.info) @@ -452,7 +461,7 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = let L = if parameters != nil: parameters.len else: 0 result.add arg[0] for i in 1..