summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2020-02-08 20:11:20 +0100
committerGitHub <noreply@github.com>2020-02-08 20:11:20 +0100
commit038f47e7b93308bef0118e1ef73edf36e39f9b91 (patch)
treec54917303100a42b8fea009aba9a195c3482aceb /doc
parent2a4aa246206e0d611c7af853b3c4308e27966079 (diff)
downloadNim-038f47e7b93308bef0118e1ef73edf36e39f9b91.tar.gz
fixes #3339 by documenting the limitations of case-statement (#13366)
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.rst29
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/manual.rst b/doc/manual.rst
index 55b14f83b..2f5673684 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -2843,6 +2843,35 @@ expanded into a list of its elements:
     of '0'..'9': echo "a number"
     else: echo "other"
 
+The ``case`` statement doesn't produce an l-value, so the following example
+won't work:
+
+.. code-block:: nim
+  type
+    Foo = ref object
+      x: seq[string]
+
+  proc get_x(x: Foo): var seq[string] =
+    # doesn't work
+    case true
+    of true:
+      x.x
+    else:
+      x.x
+
+  var foo = Foo(x: @[])
+  foo.get_x().add("asd")
+
+This can be fixed by explicitly using ``return``:
+
+.. code-block:: nim
+  proc get_x(x: Foo): var seq[string] =
+    case true
+    of true:
+      return x.x
+    else:
+      return x.x
+
 
 When statement
 --------------