Skip to content

Fix converted nullability on extract method#39134

Merged
ryzngard merged 2 commits intodotnet:masterfrom
ryzngard:issues/39075_extract_method_nullable_cast
Oct 14, 2019
Merged

Fix converted nullability on extract method#39134
ryzngard merged 2 commits intodotnet:masterfrom
ryzngard:issues/39075_extract_method_nullable_cast

Conversation

@ryzngard
Copy link
Contributor

@ryzngard ryzngard commented Oct 8, 2019

Fixes #39075

…t would cause incorrect behavior for casting of object to another type. Make sure to get type info of the cast expression, not the expression type
@ryzngard ryzngard requested a review from a team as a code owner October 8, 2019 18:14
void M()
{
object? o = null;
var s = [|(string?)o|];
Copy link
Member

Choose a reason for hiding this comment

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

Did we also want a test for the explicit case where this cast is just (string)? It's invalid code but the compiler supposedly maintains the flow state and will consider s to still be string?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more tests. Please confirm they are the behavior we want :)

@ryzngard ryzngard merged commit ba47b2f into dotnet:master Oct 14, 2019
allisonchou added a commit to allisonchou/roslyn that referenced this pull request Nov 2, 2019
allisonchou added a commit to allisonchou/roslyn that referenced this pull request Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract method drops nullable annotation on explicit cast

2 participants