diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index e6b6d5b42a33e..738b9cce2c45a 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -216,17 +216,19 @@ proc checkForErrorPragma(c: Con; t: PType; ri: PNode; opname: string; inferredFr #m.add renderTree(c.body, {renderIds}) localError(c.graph.config, ri.info, errGenerated, m) -proc makePtrType(c: var Con, baseType: PType): PType = - result = newType(tyPtr, c.idgen, c.owner) - addSonSkipIntLit(result, baseType, c.idgen) +proc genAddr(c: var Con; x: PNode): PNode = + if x.kind == nkHiddenDeref: + result = x[0] + else: + result = newNodeIT(nkHiddenAddr, x.info, makeVarType(x.typ.owner, x.typ, c.idgen)) + result.add x proc genOp(c: var Con; op: PSym; dest: PNode): PNode = var addrExp: PNode if op.typ != nil and op.typ.signatureLen > 1 and op.typ.firstParamType.kind != tyVar: addrExp = dest else: - addrExp = newNodeIT(nkHiddenAddr, dest.info, makePtrType(c, dest.typ)) - addrExp.add(dest) + addrExp = genAddr(c, dest) result = newTree(nkCall, newSymNode(op), addrExp) proc genOp(c: var Con; t: PType; kind: TTypeAttachedOp; dest, ri: PNode): PNode =