Skip to content
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

fixes #18073; fixes #14730; document notnil is only applied to local … #23084

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions doc/manual_experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ Not nil annotation
`{.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:
`not nil` annotation to exclude `nil` as a valid value. Note that only local
symbols are checked.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But globals should be checked too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trackProc function only tracks local symbols. Similarly as this case, the strictdef analysis is applied to local symbols. I suppose it's hard to analyze global symbols, which might be used in functions arbitrarily.

Globals are only checked by the direct illegal assignment if that is what you meant. I will rephrase it better.

Or I might miss something?


```nim
{.experimental: "notnil".}
Expand All @@ -577,8 +578,11 @@ All types for which `nil` is a valid value can be annotated with the
p(nil)

# and also this:
var x: PObject
p(x)
proc foo =
var x: PObject
p(x)

foo()
```

The compiler ensures that every code path initializes variables which contain
Expand Down