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

Relax enforcement on conditional nullability attributes #46201

Merged
merged 2 commits into from
Jul 28, 2020

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jul 22, 2020

Fixes #44080

For example: in void M([NotNullWhen(true)] out string? s) { s = null; return ...; } we should complain in a return true; scenario, but not in a return SomeBoolValue(); scenario.

@jcouv jcouv added this to the 16.8 milestone Jul 22, 2020
@jcouv jcouv self-assigned this Jul 22, 2020
@jcouv jcouv marked this pull request as ready for review July 22, 2020 15:37
@jcouv jcouv requested a review from a team as a code owner July 22, 2020 15:37
@cston
Copy link
Member

cston commented Jul 24, 2020

    return (bool)true; // 3

Is this not known to be true? (We shouldn't do any additional work to handle this case but it is surprising.)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:25034 in e0702f6. [](commit_id = e0702f6, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Jul 27, 2020

Tagging @RikkiGibson for a second review. Thanks

@@ -128481,6 +128447,42 @@ public new void M1<T>(System.Nullable<T?> x)
);
}

[Fact, WorkItem(43071, "https://github.com/dotnet/roslyn/issues/43071")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the implementation change affect behavior of this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No behavior change to this test, I'm just adding a test to close a different issue.

@@ -610,11 +605,6 @@ void enforceNotNullWhenForPendingReturn(PendingBranch pendingReturn, BoundExpres
enforceParameterNotNullWhen(returnStatement.Syntax, parameters, sense: true, stateWhen: pendingReturn.StateWhenTrue);
enforceParameterNotNullWhen(returnStatement.Syntax, parameters, sense: false, stateWhen: pendingReturn.StateWhenFalse);
}
else
{
enforceParameterNotNullWhen(returnStatement.Syntax, parameters, sense: true, stateWhen: pendingReturn.State);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works because we enter a split state after visiting a bool constant, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline.

@jcouv jcouv merged commit 3e5decb into dotnet:master Jul 28, 2020
@jcouv jcouv deleted the nullability-enforcement branch July 28, 2020 01:43
@ghost ghost modified the milestones: 16.8, Next Jul 28, 2020
@RikkiGibson RikkiGibson modified the milestones: Next, 16.8.P2 Aug 11, 2020
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.

Relax enforcement of conditional attributes
3 participants