Nullability enforcements when working with Deconstruct #4804
Unanswered
AlbertoMonteiro
asked this question in
Q&A
Replies: 1 comment 4 replies
-
I think it's reasonable that people want this, but that if we chose to support it, that it might end up being part of a general "associate flow state with bool locals" feature. e.g. object? x = ...;
bool isNull = x == null;
if (!isNull) x.ToString(); // ok since it seems to exhibit the same problems of:
(Success, Exception) = Result.Success();
Exception = null; // should invalidate conditional state associated with 'Success'
if (!Success) Exception.ToString(); // should warn |
Beta Was this translation helpful? Give feedback.
4 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.
-
In NET 5 we have many attributes that help the compiler to know when a field may be null or not.
But it lacks support when you use Deconstruct.
I have the given type
When I use it, the compiler gives me the proper warning if I do this:
No warning, since IsSuccess is false
But this
Result
type supports Deconstruct, and when I use it, I don't have the same benefit of this previous versionAlso, I cant use the
NotNullWhen
, since the method does not returnIs there a way to do it, and if not, are there any plans to support that kind of feature?
Beta Was this translation helpful? Give feedback.
All reactions