Should non-nullable types allow temporary assignment of possible null value? #4440
Unanswered
SoftCircuits
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
It is, which is why it will not warn if you try to consume However, the assignment of a nullable value to the non-nullable variable is enough to cause the warning. If you don't want that assignment to warn you can declare |
Beta Was this translation helpful? Give feedback.
4 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to convert code to use Nullable. But I'm finding a lot of examples where there is no change a non-nullable character could ever be assigned null, but the compiler isn't smart enough to recognize that fact so I have to unnecessarily rewrite my code, in some cases such that it becomes less efficient and/or less readable.
For example, shouldn't the compiler be smart enough to recognize that the variable
s
in the code below always gets initialized?How about something like the following. Why should method
A
have to verifyarray
is not null if it can never be null?Finally, here's one I've seen elsewhere. I get a warning here even though
s2
always gets initialized.Beta Was this translation helpful? Give feedback.
All reactions