fixes #11114
This commit is contained in:
parent
43749c4cb8
commit
1ff2b021a5
1 changed files with 5 additions and 1 deletions
|
|
@ -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
|
#echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info
|
||||||
|
|
||||||
proc asgnToResult(c: PContext, n, le, ri: PNode) =
|
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':
|
# Special typing rule: do not allow to pass 'owned T' to 'T' in 'result = x':
|
||||||
const absInst = abstractInst - {tyOwned}
|
const absInst = abstractInst - {tyOwned}
|
||||||
if ri.typ != nil and ri.typ.skipTypes(absInst).kind == tyOwned and
|
if ri.typ != nil and ri.typ.skipTypes(absInst).kind == tyOwned and
|
||||||
le.typ != nil and le.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; " &
|
localError(c.config, n.info, "cannot return an owned pointer as an unowned pointer; " &
|
||||||
"use 'owned(" & typeToString(le.typ) & ")' as the return type")
|
"use 'owned(" & typeToString(le.typ) & ")' as the return type")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue