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

Allow suppressing foreach iteration variable nullability mismatch #75432

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Oct 8, 2024

Fixes #75430.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 8, 2024
@jjonescz jjonescz changed the title Allow suppressing foreach iteration variable Allow suppressing foreach iteration variable nullability mismatch Oct 8, 2024
@jjonescz jjonescz marked this pull request as ready for review October 8, 2024 11:34
@jjonescz jjonescz requested a review from a team as a code owner October 8, 2024 11:34
@@ -8703,7 +8704,7 @@ private TypeWithState VisitConversion(
bool canConvertNestedNullability = true;
bool isSuppressed = false;

if (conversionOperand.IsSuppressed == true)
if (suppressed || conversionOperand.IsSuppressed)
Copy link
Member

@jcouv jcouv Oct 8, 2024

Choose a reason for hiding this comment

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

Could you share some details on the set up of the situation? I gather that we have two stacked conversions that are not part of the same conversion group and the operand is suppressed, but I don't understand why.
If this setup is expected, should we just dig through conversions here when looking for the IsSuppressed flag? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

We are getting here from VisitForEachIterationVariables where we call VisitConversion on node.IterationVariableType - there is no suppression in that node subtree. The suppression is in the node.Expression subtree.

Note that the pre-existing ref case similarly checks for suppression via node.Expression is not BoundConversion { Operand.IsSuppressed: true }.

@jcouv jcouv self-assigned this Oct 8, 2024
@jcouv jcouv added the Feature - Nullable Reference Types Nullable Reference Types label Oct 8, 2024
@jjonescz jjonescz requested a review from jcouv October 10, 2024 09:09
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)

@jjonescz jjonescz requested a review from a team October 11, 2024 07:34
@jcouv
Copy link
Member

jcouv commented Oct 15, 2024

@dotnet/roslyn-compiler for second review. Thanks

@RikkiGibson RikkiGibson self-assigned this Oct 16, 2024
@@ -8703,7 +8704,7 @@ private TypeWithState VisitConversion(
bool canConvertNestedNullability = true;
bool isSuppressed = false;

if (conversionOperand.IsSuppressed == true)
if (suppressed || conversionOperand.IsSuppressed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to unify the suppressed parameter with the isSuppressed local?

@jjonescz jjonescz requested a review from RikkiGibson October 18, 2024 08:44
@jcouv
Copy link
Member

jcouv commented Oct 23, 2024

@RikkiGibson Please take another look. Thanks

@jcouv
Copy link
Member

jcouv commented Oct 30, 2024

@RikkiGibson Please take another look. Thanks

@jjonescz jjonescz enabled auto-merge (squash) October 31, 2024 09:17
@jjonescz jjonescz merged commit 455196f into dotnet:main Oct 31, 2024
24 checks passed
@jjonescz jjonescz deleted the 75430-ForeachNullSuppression branch October 31, 2024 10:29
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 31, 2024
@jjonescz jjonescz removed this from the Next milestone Nov 25, 2024
@jjonescz jjonescz added this to the 17.13 P2 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Nullable Reference Types Nullable Reference Types untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nullability mismatch in non-ref foreach cannot be suppressed
3 participants