borrow checking refinements (#15290)

* added basic borrowing test
This commit is contained in:
Andreas Rumpf
2020-09-09 14:19:22 +02:00
committed by GitHub
parent ccd77b42af
commit 217675cf84
3 changed files with 39 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
discard """
errormsg: "cannot borrow"
nimout: '''tcannot_borrow.nim(16, 7) Error: cannot borrow meh; what it borrows from is potentially mutated
tcannot_borrow.nim(17, 3) the mutation is here
tcannot_borrow.nim(16, 7) is the statement that connected the mutation to the parameter'''
line: 16
"""
{.experimental: "views".}
type
Foo = object
field: string
proc dangerous(s: var seq[Foo]) =
let meh: lent Foo = s[0]
s.setLen 0
echo meh.field