summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-05-02 08:51:37 +0200
committerAraq <rumpf_a@web.de>2019-05-02 09:39:57 +0200
commit1ff2b021a5affd66309849e81b47823cc821b5fc (patch)
tree150f5915ed0a92293499356ff1109399badaa7ea
parent43749c4cb89472ed949ee3bea405148bf777566b (diff)
downloadNim-1ff2b021a5affd66309849e81b47823cc821b5fc.tar.gz
fixes #11114
-rw-r--r--compiler/semexprs.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index bd7ee1ab3..38e079fdd 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1527,11 +1527,15 @@ proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
       #echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info
 
 proc asgnToResult(c: PContext, n, le, ri: PNode) =
+  proc scopedLifetime(c: PContext; ri: PNode): bool {.inline.} =
+    result = (ri.kind in nkCallKinds+{nkObjConstr}) or
+      (ri.kind == nkSym and ri.sym.owner == c.p.owner)
+
   # Special typing rule: do not allow to pass 'owned T' to 'T' in 'result = x':
   const absInst = abstractInst - {tyOwned}
   if ri.typ != nil and ri.typ.skipTypes(absInst).kind == tyOwned and
       le.typ != nil and le.typ.skipTypes(absInst).kind != tyOwned and
-      ri.kind in nkCallKinds+{nkObjConstr}:
+      scopedLifetime(c, ri):
     localError(c.config, n.info, "cannot return an owned pointer as an unowned pointer; " &
       "use 'owned(" & typeToString(le.typ) & ")' as the return type")