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

Input param postconditions #49576

Merged
merged 2 commits into from
Dec 7, 2020

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Nov 23, 2020

Closes #48605
Closes #48134
Closes #49136

Implements the change described in dotnet/csharplang#4102 (comment). Also fixes a bug where a null-conditional expression with a type T where T : class? had flow state MaybeNull when it should actually have flow state MaybeDefault.

Note that while arguments to user-defined conversions have their state updated when the conversion causes a nullable warning, we don't actually honor the postcondition on the conversion parameter. Filed #49575 to follow-up-- I think parameter postconditions on a user-defined conversion are a pretty edge case, so probably won't prioritize it.

@RikkiGibson RikkiGibson force-pushed the input-param-postconditions branch 2 times, most recently from 3474ceb to 8f8f037 Compare November 24, 2020 00:10
@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@jcouv jcouv self-assigned this Dec 2, 2020
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 1)

@jcouv jcouv added this to the 16.9 milestone Dec 3, 2020
@RikkiGibson RikkiGibson requested a review from a team December 3, 2020 00:25
@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@@ -5308,7 +5324,10 @@ private VisitArgumentResult VisitArgumentEvaluate(BoundExpression argument, RefK
stateForLambda: result.StateForLambda);

// If the parameter has annotations, we perform an additional check for nullable value types
Copy link
Member

Choose a reason for hiding this comment

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

nullable value types [](start = 96, length = 20)

Is this just for nullable value types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for example in the case of a parameter [DisallowNull] string? s we can adjust the type to just string and then visit the conversion. But in the case of [DisallowNull] int? i we can't adjust the type in that way. SharpLab. Note particularly the difference in diagnostic IDs.

@RikkiGibson
Copy link
Contributor Author

The validation run passes CloudBuild so will merge this now.

@RikkiGibson RikkiGibson merged commit 61a287a into dotnet:master Dec 7, 2020
@ghost ghost modified the milestones: 16.9, Next Dec 7, 2020
@RikkiGibson RikkiGibson deleted the input-param-postconditions branch December 7, 2020 21:45
@dibarbet dibarbet modified the milestones: Next, 16.9.P3 Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment