summary refs log tree commit diff stats
path: root/doc/manual_experimental.rst
diff options
context:
space:
mode:
authorRory O’Kane <rory@roryokane.com>2020-04-21 08:54:43 -0400
committerGitHub <noreply@github.com>2020-04-21 14:54:43 +0200
commitb8b0e9b21d0b6da8c807efc6bbb339cd89c6236f (patch)
treea1728701e1a31b5aed6689c96077c9c0aae90e8e /doc/manual_experimental.rst
parent04c326569bdafa619d6596d2d674d3acbcc1ecf3 (diff)
downloadNim-b8b0e9b21d0b6da8c807efc6bbb339cd89c6236f.tar.gz
docs: move `not nil` to the experimental page (#14027)
When I heard that this feature existed, and found the 2018 changelog entry that said `not nil` was made experimental (https://github.com/nim-lang/Nim/blob/devel/changelogs/changelog_0_19_0.md#changes-affecting-backwards-compatibility), I looked for `not nil` documentation in https://nim-lang.org/docs/manual_experimental.html. When I didn’t find it there, I initially assumed the feature had no documentation. This change moves the documentation to where readers will expect it.

As well as moving the text to another file, I added instructions for enabling the experimental feature and tweaked some wording.
Diffstat (limited to 'doc/manual_experimental.rst')
-rw-r--r--doc/manual_experimental.rst30
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/manual_experimental.rst b/doc/manual_experimental.rst
index 8c61c1217..f65c0933b 100644
--- a/doc/manual_experimental.rst
+++ b/doc/manual_experimental.rst
@@ -340,6 +340,36 @@ This operator will be matched against assignments to missing fields.
   a.b = c # becomes `.=`(a, b, c)
 
 
+Not nil annotation
+==================
+
+**Note:** This is an experimental feature. It can be enabled with
+``{.experimental: "notnil"}``.
+
+All types for which ``nil`` is a valid value can be annotated with the ``not
+nil`` annotation to exclude ``nil`` as a valid value:
+
+.. code-block:: nim
+  {.experimental: "notnil"}
+  
+  type
+    PObject = ref TObj not nil
+    TProc = (proc (x, y: int)) not nil
+
+  proc p(x: PObject) =
+    echo "not nil"
+
+  # compiler catches this:
+  p(nil)
+
+  # and also this:
+  var x: PObject
+  p(x)
+
+The compiler ensures that every code path initializes variables which contain
+non-nilable pointers. The details of this analysis are still to be specified
+here.
+
 
 Concepts
 ========