-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: move not nil
to the experimental page
#14027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. except it doesn't.... so I'd reword for honesty as:
when true:
{.experimental: "notnil"}
type
TObj = object
PObject = ref TObj not nil
TProc = (proc (x, y: int)) not nil
proc p(x: PObject) =
echo "not nil"
echo x == nil
# compiler catches this:
# p(nil)
# and also this:
var x: PObject
p(x) prints:
maybe you could pull up some other compelling example from #13808 /cc @zah |
||
|
||
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 | ||
======== | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nim rst2html foo.rst
or for whole docs you can./koch docs