summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-10-26 21:08:57 +0100
committerGitHub <noreply@github.com>2020-10-26 21:08:57 +0100
commitcf01945f54f099c268850c720986ad6c9bbdb51e (patch)
treeb8c219999c8e4ce7fab6b1a8aa1db6c1808237fe /compiler
parent3a69f14621156358e2fc154881f60459d04814a1 (diff)
downloadNim-cf01945f54f099c268850c720986ad6c9bbdb51e.tar.gz
ensure the Nim compiler works with --experimental:strictFuncs --experimental:views [backport:1.4] (#15737)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/varpartitions.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim
index f831d33cc..49221654d 100644
--- a/compiler/varpartitions.nim
+++ b/compiler/varpartitions.nim
@@ -545,6 +545,9 @@ proc borrowingCall(c: var Partitions; destType: PType; n: PNode; i: int) =
     localError(c.config, n[i].info, "cannot determine the target of the borrow")
 
 proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
+  proc mutableParameter(n: PNode): bool {.inline.} =
+    result = n.kind == nkSym and n.sym.kind == skParam and n.sym.typ.kind == tyVar
+
   if dest.kind == nkSym:
     if directViewType(dest.typ) != noView:
       borrowFrom(c, dest.sym, src)
@@ -559,7 +562,11 @@ proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
         if vid >= 0:
           c.s[vid].flags.incl viewDoesMutate
     of immutableView:
-      localError(c.config, dest.info, "attempt to mutate a borrowed location from an immutable view")
+      if dest.kind == nkBracketExpr and dest[0].kind == nkHiddenDeref and
+          mutableParameter(dest[0][0]):
+        discard "remains a mutable location anyhow"
+      else:
+        localError(c.config, dest.info, "attempt to mutate a borrowed location from an immutable view")
     of noView: discard "nothing to do"
 
 proc containsPointer(t: PType): bool =