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 initial binding always binds to natural type #48205

Merged
merged 5 commits into from
Oct 5, 2020

Conversation

333fred
Copy link
Member

@333fred 333fred commented Sep 30, 2020

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1198816/, which is about CSharpOperationFactory.CreateInternal being passed a node it does not expect. I looked through all the places in the binder where we use BindValue and ensured the results were being correctly bound to a natural type, even if there was some error. I found 2 such cases:

  • Array rank specifiers were not being bound to their natural type if they had some error.
  • if conditions were not being bound to their natural type if they had some error. This is the case that results in the specific stack pattern from the watson, where a BoundConversion sat on top of a BoundUnconvertedObjectCreationExpression.

In both of these cases, unconverted results were passed to the factory, which cannot handle nodes of these types and threw.

@333fred 333fred requested a review from a team as a code owner September 30, 2020 21:17
@333fred
Copy link
Member Author

333fred commented Sep 30, 2020

@dotnet/roslyn-compiler for reviews please.

@333fred
Copy link
Member Author

333fred commented Sep 30, 2020

@dotnet/roslyn-compiler for a second review please.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 1, 2020

@333fred

In both of these cases, unconverted results were passed to the factory, which cannot handle nodes of these types and threw.

I think @gafter added an assert somewhere in flow analysis to catch all the nodes that haven't been properly adjusted. I am curious if these cases are caught by that assert. If they are not, perhaps it would be useful to understand why and adjust the assert accordingly. #Closed

@@ -3165,6 +3165,10 @@ private BoundExpression BindArrayDimension(ExpressionSyntax dimension, Diagnosti
hasErrors = true;
}
}
else
{
size = BindToNaturalType(size, diagnostics);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 1, 2020

Choose a reason for hiding this comment

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

BindToNaturalType [](start = 27, length = 17)

BindToTypeForErrorRecovery #Closed

@@ -3165,6 +3165,10 @@ private BoundExpression BindArrayDimension(ExpressionSyntax dimension, Diagnosti
hasErrors = true;
}
}
else
{
size = BindToNaturalType(size, diagnostics);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 1, 2020

Choose a reason for hiding this comment

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

diagnostics [](start = 51, length = 11)

I don't think we want to collect diagnostics on this code path. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 1, 2020

Done with review pass (iteration 4) #Closed

@333fred
Copy link
Member Author

333fred commented Oct 1, 2020

I think gafter added an assert somewhere in flow analysis to catch all the nodes that haven't been properly adjusted. I am curious if these cases are caught by that assert. If they are not, perhaps it would be useful to understand why and adjust the assert accordingly.

Running the added tests without my fix triggers that assert. It looks like we didn't have test coverage for this path. It also looks like the path is missing checking for unconverted address of operators (it was added in Neal's branch, which was in development at the same time as mine, so the address of operator was never added). I'll add that and a test here, as that would also crash.

@333fred
Copy link
Member Author

333fred commented Oct 1, 2020

It also looks like the path is missing checking for unconverted address of operators (it was added in Neal's branch, which was in development at the same time as mine, so the address of operator was never added). I'll add that and a test here, as that would also crash.

Actually, I'm going to do this change on master. It looks like it's all handled appropriately currently.

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 (iteration 5)

@333fred 333fred merged commit 42f02a6 into dotnet:release/dev16.8 Oct 5, 2020
@333fred 333fred deleted the iop-crash-target-typed-new branch October 5, 2020 18:14
333fred added a commit that referenced this pull request Oct 5, 2020
…elease/dev16.8-to-master

* upstream/release/dev16.8:
  Handle indexers in nested object initializers (#48168)
  Ensure initial binding always binds to natural type (#48205)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants