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

Handle patterns in populate switch expressions #50984

Conversation

Youssef1313
Copy link
Member

Fixes #50982

Not sure of the fix quality tbh.

@Youssef1313 Youssef1313 force-pushed the handle-patterns-in-populate-switch-expression branch from b7ab60a to c39956f Compare February 3, 2021 20:40
@@ -962,7 +962,7 @@ void Method()
(MyEnum)0 => 1,
(MyEnum)1 => 2,
""Mismatching constant"" => 3,
_ => throw new System.NotImplementedException(),
MyEnum.FizzBuzz => throw new System.NotImplementedException(),
Copy link
Member Author

Choose a reason for hiding this comment

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

When "Mismatching constant" was encountered, the analyzer considered the switch as "complete". Hence, it failed to 'add missing cases'.

The "mismatching constant" is a compile-error anyway. So it probably doesn't matter a lot.

Comment on lines 1041 to +1043
Bar.Option2 => 2,
null => null,
_ => throw new System.NotImplementedException(),
Bar.Option3 => throw new System.NotImplementedException(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is misleading. It's named TestAddMissingCasesForNullableEnum, but the enum in it isn't nullable. Do you want me to make the enum nullable in it?

Copy link
Member

Choose a reason for hiding this comment

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

dont' change existing tests. you can rename them and/or add new tests. thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

@CyrusNajmabadi Well, I'll leave the test case and test name as-is for now. Only the expected result is updated.

Copy link
Member

Choose a reason for hiding this comment

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

wfm. feel free to update the name as well if you want. but genrally don't make the test fit the name, make the name fit the test. and we feel there is a test hole, where no test checks the original name's case, then we can add that :)

@CyrusNajmabadi
Copy link
Member

Want me to merge? or are you still working on things here?

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi You can merge.
Tests in this file may be updated in a follow-up. They need work to move to the new testing library, so that we can test different code actions individually (I assume there is no way to do that with the legacy testing infrastructure).

Let me know if you want me to file an issue for that?

@CyrusNajmabadi
Copy link
Member

Let me know if you want me to file an issue for that?

No issue needed. We generally are not good about effectively managing such issues. So the repo just fills up without end.

Base automatically changed from master to main March 3, 2021 23:53
@Youssef1313
Copy link
Member Author

@CyrusNajmabadi Anything left to merge?

@CyrusNajmabadi
Copy link
Member

Thanks!

@CyrusNajmabadi CyrusNajmabadi merged commit 2d20863 into dotnet:main Mar 5, 2021
@Youssef1313 Youssef1313 deleted the handle-patterns-in-populate-switch-expression branch March 5, 2021 17:55
@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 5, 2021
@allisonchou allisonchou added this to the Next milestone Mar 12, 2021
@allisonchou allisonchou removed this from the Next milestone Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IDE0072: False positive when using switch expression and pattern matching with "or"
4 participants