-
-
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
--nilseqs:on
should show warning when nil
is used; or add --nilseqs:warning
option
#8668
Comments
It's not clear what to do. |
well, in nim-regex case, compiling the code did show where the error is, I had |
it only shows either 0 or 1 error depending on
I'm not talking about what should be the value of The code owner will have to fix his code on a case by case basis (sometimes it requires adding a field in some data structure as @Araq did in dae5450 :
with my suggestion of a warning, i'll be much more likely the code will end up being patched soon. Otherwise I currently HAVE to use |
But if we warn about this, we still need to decide how to compile it.
Well |
Ok, the snippet below show's there's just no good default behavior, it'll be a source of bugs (worst case: potentially subtle ones that only trigger in rare conditions, or only in production etc). var s:string
if s is nil:
initialize1()
for i in 0..10:
if s is nil:
s = ""
initialize2()
restOfCode()
* behavior 1: s is nil: false for ""
=> initialize1 never called (previous behavior: once) => BUG
* behavior 2: s is nil: true for ""
=> initialize2 called more than once (previous behavior: once) => BUG how about this:
rationale
|
One year later and people had enough time to update their code -- with or without this possible improvement. |
latest devel makes
nil
string an error instead of a deprecation warning; it breaks some packages, eg nitely/nim-regex#17using
--nilseqs:on
is too blunt of a workaround as it doesn't show where the code needs to be fixed, so there's no way currently to list all places where a nil is wrongly used in a string/seq context. This is especially bad in case of third party (eg nimble) dependencies: right now I dont' have easy way to tell which packages will fail because ofnil
unless I fix errors in all these 3rd party packages 1 by one, which is impracticalproposal
either make
--nilseqs:on
show a warning whennil
is usedor add an option--nilseqs:warning
to do just thatEDIT (minor point):
Error: usage of '==' is a user-defined error
is confusing (/cc @Araq)bugs/compiler/t18_isNil.nim:
=> could we make it either a regular mismatch error (showing overloads of
==
) orError: <nil> invalid value for a string
regressions caused by nil
The text was updated successfully, but these errors were encountered: