summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-05-26 23:10:34 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-27 21:29:02 +0200
commit49e686ab4e8103173ecb39cc16896eb979ddf9ce (patch)
tree61c40522d19e63c3bd86251a2a62bb57cf08022a /doc
parent247fa431de9587b59978a1c8a7b20da6fe44f95e (diff)
downloadNim-49e686ab4e8103173ecb39cc16896eb979ddf9ce.tar.gz
fixes #1286; object case transitions are now sound
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.rst21
1 files changed, 17 insertions, 4 deletions
diff --git a/doc/manual.rst b/doc/manual.rst
index 615b8e302..fafc1ea5b 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -1538,10 +1538,23 @@ the ``case`` statement: The branches in a ``case`` section may be indented too.
 
 In the example the ``kind`` field is called the `discriminator`:idx:\: For
 safety its address cannot be taken and assignments to it are restricted: The
-new value must not lead to a change of the active object branch. For an object
-branch switch ``system.reset`` has to be used. Also, when the fields of a
-particular branch are specified during object construction, the corresponding
-discriminator value must be specified as a constant expression.
+new value must not lead to a change of the active object branch. Also, when the
+fields of a particular branch are specified during object construction, the
+corresponding discriminator value must be specified as a constant expression.
+
+Instead of changing the active object branch, replace the old object in memory
+with a new one completely:
+
+.. code-block:: nim
+
+  var x = Node(kind: nkAdd, leftOp: Node(kind: nkInt, intVal: 4),
+                            rightOp: Node(kind: nkInt, intVal: 2))
+  # change the node's contents:
+  x[] = NodeObj(kind: nkString, strVal: "abc")
+
+
+Starting with version 0.20 ``system.reset`` cannot be used anymore to support
+object branch changes as this never was completely memory safe.
 
 As a special rule, the discriminator kind can also be bounded using a ``case``
 statement. If possible values of the discriminator variable in a