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

Ensure unconverted elements are converted when on LHS #76675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

333fred
Copy link
Member

@333fred 333fred commented Jan 8, 2025

Fixes #76444.

@333fred 333fred requested a review from a team as a code owner January 8, 2025 03:13
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 8, 2025
@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@333fred
Copy link
Member Author

333fred commented Jan 9, 2025

@AlekseyTs addressed your feedback.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 2)

@333fred
Copy link
Member Author

333fred commented Jan 9, 2025

@dotnet/roslyn-compiler for a second review of this fairly simple PR.

|| op1 is BoundParameter or BoundLocal
|| op1.HasAnyErrors);

if (op1.HasAnyErrors)
Copy link
Member

Choose a reason for hiding this comment

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

HasAnyErrors

This check seems too broad since the error could in a nested expression with no error on op1 directly. In short, it seems surprising we're binding for error recovery in that situation.

If we're just trying to ensure op1 is converted, would it make sense to do that explicitly?

if (op1.NeedsToBeConverted())
{
    op1 = BindToNaturalType(op1, BindingDiagnosticBag.Discard, reportNoTargetType: false);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

My original approach did effectively this. Aleksey was concerned, rightly so, that discarding diagnostics here is probably not safe, as there is no guarantee that errors have been reported for op1. I do not think that it is surprising that we bind for error recovery in this scenario when we know that there are errors; in such a scenario, we simply want to be able to give the most precise info that we can.

Copy link
Member

Choose a reason for hiding this comment

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

discarding diagnostics here is probably not safe, as there is no guarantee that errors have been reported for op1.

In that case, we could pass in the diagnostics instance.

I do not think that it is surprising that we bind for error recovery in this scenario when we know that there are errors

HasAnyErrors indicates there is an error somewhere beneath op1, but the outermost node op1 might be otherwise valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you would prefer, I can switch to just checking HasErrors, rather than HasAnyErrors, so it's only on the node itself.

@@ -1506,6 +1517,7 @@ private BoundAssignmentOperator BindAssignment(
}
else
{
op1 = BindToTypeForErrorRecovery(op1);
Copy link
Member

Choose a reason for hiding this comment

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

op1 = BindToTypeForErrorRecovery(op1);

Are we testing this change?

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 cannot find a way to hit this line in a way that would fail without this binding; however, I believe that, since this is an error scenario anyways, more defensive coding ensuring that this goes through proper conversion checks is a good thing. If you want, I can add an assert to fail if an interesting case ever goes through here, ie Debug.Assert(op1 is BoundParameter or BoundLocal || !op1.NeedsToBeConverted(), "It is currently believed that this isn't hittable. If you trigger this assert, please an explicit test!");?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for investigating. I don't think we need an assert.

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

Unexpected value 'UnconvertedInterpolatedString' in CSharpOperationFactory
3 participants