Skip to content

Commit

Permalink
fix #15958
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldome committed Nov 14, 2020
1 parent c1664f9 commit e4e6c48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ proc ccgIntroducedPtr(conf: ConfigRef; s: PSym, retType: PType): bool =
result = false
# first parameter and return type is 'lent T'? --> use pass by pointer
if s.position == 0 and retType != nil and retType.kind == tyLent:
result = pt.kind != tyVar
result = pt.kind notin {tyVar, tyArray}

proc fillResult(conf: ConfigRef; param: PNode) =
fillLoc(param.sym.loc, locParam, param, ~"Result",
Expand Down
11 changes: 11 additions & 0 deletions tests/lent/tbasic_lent_check.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discard """
targets: "c cpp"
output: "1"
"""

Expand All @@ -14,3 +15,13 @@ proc main =
doAssert(not compiles(passToVar(viewInto(x))))

main()


#------------------------------------------------------------------------------
# issue #15958

block:
proc byLent[T](a: T): lent T = a
let a = [11,12]
doAssert byLent(a) == [11,12]
doAssert byLent(a).unsafeAddr == a.unsafeAddr

0 comments on commit e4e6c48

Please sign in to comment.