-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
base: main
Are you sure you want to change the base?
Conversation
Done with review pass (commit 1) |
@AlekseyTs addressed your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 2)
@dotnet/roslyn-compiler for a second review of this fairly simple PR. |
|| op1 is BoundParameter or BoundLocal | ||
|| op1.HasAnyErrors); | ||
|
||
if (op1.HasAnyErrors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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!");
?
There was a problem hiding this comment.
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.
Fixes #76444.