Skip to content
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

Merged
merged 3 commits into from
Jan 1, 2019
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Dec 21, 2018

Fixes #31519

I'm going to wait for #31978 to make some improvements to this PR.

@jcouv jcouv added this to the 16.0.P2 milestone Dec 21, 2018
@jcouv jcouv self-assigned this Dec 21, 2018
@jcouv jcouv requested a review from a team as a code owner December 21, 2018 07:23
{
async void M(System.Threading.Tasks.Task<string>? task)
{
await task; // warn
Copy link
Member

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()?

Copy link
Member Author

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.

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 21, 2018
@333fred
Copy link
Member

333fred commented Dec 21, 2018

Worth adding tests for nullable of ValueTask as well?

@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 27, 2018
int slot = MakeSlot(receiverOpt);
if (slot > 0)

if (receiverOpt != null)
Copy link
Member

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.

@333fred
Copy link
Member

333fred commented Dec 28, 2018

    private void CheckPossibleNullReceiver(BoundExpression receiverOpt, bool checkNullableValueType = false, SyntaxNode syntaxOpt = null)

Consider adding tests for the other users of CheckPossibleNullReceiver.


Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:4887 in 5537bea. [](commit_id = 5537bea, deletion_comment = False)

@333fred
Copy link
Member

333fred commented Dec 28, 2018

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);
Copy link
Member

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?

Copy link
Member Author

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.

@jcouv jcouv merged commit 2ea8c69 into dotnet:master Jan 1, 2019
@jcouv jcouv deleted the await-nullable branch January 1, 2019 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants