From 663b1f2c9665809f914e618ceaecaf4088d957f9 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 24 Mar 2019 16:43:40 +0100 Subject: [PATCH] newruntime: bugfixes --- compiler/injectdestructors.nim | 5 ++++- compiler/semexprs.nim | 3 +++ compiler/types.nim | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index e9323834e3..eb8f86e8e8 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -354,7 +354,7 @@ proc genSink(c: Con; t: PType; dest, ri: PNode): PNode = # in rare cases only =destroy exists but no sink or assignment # (see Pony object in tmove_objconstr.nim) # we generate a fast assignment in this case: - result = newTree(nkFastAsgn, dest, ri) + result = newTree(nkFastAsgn, dest) proc genCopy(c: Con; t: PType; dest, ri: PNode): PNode = if tfHasOwned in t.flags: @@ -598,6 +598,9 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = else: ri2[i] = pArg(ri[i], c, isSink = true) result.add ri2 + of nkNilLit: + result = genSink(c, dest.typ, dest, ri) + result.add ri of nkSym: if isSinkParam(ri.sym): # Rule 3: `=sink`(x, z); wasMoved(z) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5cc2e96a60..de2b6d782a 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1518,6 +1518,8 @@ proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} = n.sons[1] = takeImplicitAddr(c, ri, x.typ.kind == tyLent) x.typ.flags.incl tfVarIsPtr #echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info + +proc asgnToResult(c: PContext, n, le, ri: PNode) = # Special typing rule: do not allow to pass 'owned T' to 'T' in 'result = x': if ri.typ != nil and ri.typ.skipTypes(abstractInst).kind == tyOwned and le.typ != nil and le.typ.skipTypes(abstractInst).kind != tyOwned: @@ -1614,6 +1616,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode = c.p.owner.typ.sons[0] = rhsTyp else: typeMismatch(c.config, n.info, lhs.typ, rhsTyp) + asgnToResult(c, n, n.sons[0], n.sons[1]) n.sons[1] = fitNode(c, le, rhs, goodLineInfo(n[1])) liftTypeBoundOps(c, lhs.typ, lhs.info) diff --git a/compiler/types.nim b/compiler/types.nim index 069d663acd..a84cf651e4 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1277,7 +1277,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, # prevent cascading errors: result = nil of tyOwned: - if t.len == 1 and t.sons[0].kind in {tyRef, tyPtr}: + if t.len == 1 and t.sons[0].skipTypes(abstractInst).kind in {tyRef, tyPtr, tyProc}: result = typeAllowedAux(marker, t.lastSon, skVar, flags+{taHeap}) else: result = t