-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Await should check null-state of expression #31981
Conversation
{ | ||
async void M(System.Threading.Tasks.Task<string>? task) | ||
{ | ||
await task; // warn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth testing await x?.M()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add.
I expect this produces a safety warning for awaiting something that could be null
, but that we don't update the state of x
to non-null (if the await didn't throw). So there will be cascading diagnostics, which we could suppress.
Worth adding tests for nullable of ValueTask as well? |
40f660a
to
d2429a8
Compare
d2429a8
to
d6b4363
Compare
int slot = MakeSlot(receiverOpt); | ||
if (slot > 0) | ||
|
||
if (receiverOpt != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this check, we're already in an if with this condition.
Consider adding tests for the other users of Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:4887 in 5537bea. [](commit_id = 5537bea, deletion_comment = False) |
Done review pass (commit 2) |
@@ -4491,6 +4491,7 @@ private TypeSymbolWithAnnotations InferResultNullabilityOfBinaryLogicalOperator( | |||
public override BoundNode VisitAwaitExpression(BoundAwaitExpression node) | |||
{ | |||
var result = base.VisitAwaitExpression(node); | |||
CheckPossibleNullReceiver(node.Expression); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the case where GetAwaiter
is an extension method which takes a nullable receiver? What should the code do in that case and is it handled / tested here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a test, but I expect the behavior is the same as for invocations. Namely, we still warn. That was an explicit decision in a previous PR, but we could adjust later.
Fixes #31519
I'm going to wait for #31978 to make some improvements to this PR.