Null state when comparing unconstrained T to null #4201
Unanswered
RikkiGibson
asked this question in
Q&A
Replies: 0 comments
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.
-
There are some slightly interesting nullable scenarios when it comes to comparing unconstrained/
class?
-constrained T tonull
. I opened an issue a while back to try and address what I thought was a bug (demonstrated below).SharpLab
Basically, our shipped behavior is that comparing a T to
null
does not "downgrade" the flow state to MaybeDefault. This seems to be because we don't have a test that "upgrades" a variable's state from MaybeDefault to MaybeNull, i.e. that tests that a variable contains a valid value for its declared type.If we were to change this to resolve the strange behavior in the above sample, we would introduce potentially unpleasant behaviors other scenarios. For example, if you null-test some input to safely access members on it, we would suddenly start doubting that the input is a valid value of the input type, and we won't let you return it.
SharpLab
After studying this scenario for a little while, it feels like something we should leave alone, but it's odd enough that I thought I would raise the question anyway. Should we change any behavior around this?
Beta Was this translation helpful? Give feedback.
All reactions