view types: spec changes (#18226)

* view types: spec changes

* Update doc/manual_experimental.rst

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* Update doc/manual_experimental.rst

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
Andreas Rumpf 2021-06-10 16:49:17 +02:00 • committed by GitHub
commit 2ea7287217
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 24 deletions

View file

@ -572,7 +572,7 @@ proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
borrowFrom(c, dest.sym, src)
elif dest.kind in {nkHiddenDeref, nkDerefExpr, nkBracketExpr}:
case directViewType(dest[0].typ)
of mutableView:
of mutableView, immutableView:
# we do not borrow, but we use the view to mutate the borrowed
# location:
let viewOrigin = pathExpr(dest, c.owner)
@ -580,12 +580,13 @@ proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
let vid = variableId(c, viewOrigin.sym)
if vid >= 0:
c.s[vid].flags.incl viewDoesMutate
of immutableView:
#[of immutableView:
if dest.kind == nkBracketExpr and dest[0].kind == nkHiddenDeref and
mutableParameter(dest[0][0]):
discard "remains a mutable location anyhow"
else:
localError(c.g.config, dest.info, "attempt to mutate a borrowed location from an immutable view")
]#
of noView: discard "nothing to do"
proc containsPointer(t: PType): bool =