Skip to content

Commit b8b0e9b

Browse files
authored
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.
1 parent 04c3265 commit b8b0e9b

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

doc/manual.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,32 +1851,6 @@ details like this when mixing garbage collected data with unmanaged memory.
18511851
.. XXX finalizers for traced objects
18521852
18531853
1854-
Not nil annotation
1855-
------------------
1856-
1857-
All types for which ``nil`` is a valid value can be annotated to
1858-
exclude ``nil`` as a valid value with the ``not nil`` annotation:
1859-
1860-
.. code-block:: nim
1861-
type
1862-
PObject = ref TObj not nil
1863-
TProc = (proc (x, y: int)) not nil
1864-
1865-
proc p(x: PObject) =
1866-
echo "not nil"
1867-
1868-
# compiler catches this:
1869-
p(nil)
1870-
1871-
# and also this:
1872-
var x: PObject
1873-
p(x)
1874-
1875-
The compiler ensures that every code path initializes variables which contain
1876-
non nilable pointers. The details of this analysis are still to be specified
1877-
here.
1878-
1879-
18801854
Procedural type
18811855
---------------
18821856
A procedural type is internally a pointer to a procedure. ``nil`` is

doc/manual_experimental.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,36 @@ This operator will be matched against assignments to missing fields.
340340
a.b = c # becomes `.=`(a, b, c)
341341
342342
343+
Not nil annotation
344+
==================
345+
346+
**Note:** This is an experimental feature. It can be enabled with
347+
``{.experimental: "notnil"}``.
348+
349+
All types for which ``nil`` is a valid value can be annotated with the ``not
350+
nil`` annotation to exclude ``nil`` as a valid value:
351+
352+
.. code-block:: nim
353+
{.experimental: "notnil"}
354+
355+
type
356+
PObject = ref TObj not nil
357+
TProc = (proc (x, y: int)) not nil
358+
359+
proc p(x: PObject) =
360+
echo "not nil"
361+
362+
# compiler catches this:
363+
p(nil)
364+
365+
# and also this:
366+
var x: PObject
367+
p(x)
368+
369+
The compiler ensures that every code path initializes variables which contain
370+
non-nilable pointers. The details of this analysis are still to be specified
371+
here.
372+
343373

344374
Concepts
345375
========

0 commit comments

Comments
 (0)