summary refs log tree commit diff stats
path: root/tests/views
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-09-28 20:02:07 +0800
committerGitHub <noreply@github.com>2022-09-28 14:02:07 +0200
commitfdc6b0fb6e1b7272f32f177da4e44d9055c00b67 (patch)
treec365b463d3fb698f34bb42efcc3f0132707390a8 /tests/views
parent18cea8e9bd9b747e085974d1afc99fd71fe19fa6 (diff)
downloadNim-fdc6b0fb6e1b7272f32f177da4e44d9055c00b67.tar.gz
fixes #19986; mutable view from immutable location (#20134)
* fixes #19986; mutable view from immutable location

* fixes the tests
Diffstat (limited to 'tests/views')
-rw-r--r--tests/views/t19986.nim42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/views/t19986.nim b/tests/views/t19986.nim
new file mode 100644
index 000000000..85a7cf97d
--- /dev/null
+++ b/tests/views/t19986.nim
@@ -0,0 +1,42 @@
+discard """
+  cmd: '''nim check --hints:off $file'''
+  action: reject
+nimout: '''
+t19986.nim(19, 7) Error: 'foo' borrows from the immutable location 'a' and attempts to mutate it
+t19986.nim(28, 7) Error: 'foo' borrows from the immutable location 'a' and attempts to mutate it
+t19986.nim(37, 7) Error: 'foo' borrows from the immutable location 'a' and attempts to mutate it
+'''
+"""
+
+{.experimental: "views".}
+
+type
+  Object = object
+    id: int
+
+proc foo() =
+  let a = Object(id: 3)
+  var foo: var Object = a
+
+  foo.id = 777
+  echo a
+
+foo()
+
+proc bar() =
+  let a = "123"
+  var foo: var string = a
+
+  foo[0] = '7'
+  echo a
+
+bar()
+
+proc main() =
+  let a = 3
+  var foo: var int = a
+
+  foo = 777
+  echo a
+
+main()