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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Language 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
2 participants