File tree 2 files changed +30
-26
lines changed 2 files changed +30
-26
lines changed Original file line number Diff line number Diff line change @@ -1851,32 +1851,6 @@ details like this when mixing garbage collected data with unmanaged memory.
1851
1851
.. XXX finalizers for traced objects
1852
1852
1853
1853
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
-
1880
1854
Procedural type
1881
1855
---------------
1882
1856
A procedural type is internally a pointer to a procedure. ``nil `` is
Original file line number Diff line number Diff line change @@ -340,6 +340,36 @@ This operator will be matched against assignments to missing fields.
340
340
a.b = c # becomes `.=`(a, b, c)
341
341
342
342
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
+
343
373
344
374
Concepts
345
375
========
You can’t perform that action at this time.
0 commit comments