Skip to content

Handle patterns in populate switch expressions#50984

Merged
CyrusNajmabadi merged 8 commits intodotnet:mainfrom
Youssef1313:handle-patterns-in-populate-switch-expression
Mar 5, 2021
Merged

Handle patterns in populate switch expressions#50984
CyrusNajmabadi merged 8 commits intodotnet:mainfrom
Youssef1313:handle-patterns-in-populate-switch-expression

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

Fixes #50982

Not sure of the fix quality tbh.

@ghost ghost added the Area-IDE label Feb 3, 2021
Youssef1313 and others added 2 commits February 3, 2021 22:26
@Youssef1313 Youssef1313 force-pushed the handle-patterns-in-populate-switch-expression branch from b7ab60a to c39956f Compare February 3, 2021 20:40
(MyEnum)1 => 2,
""Mismatching constant"" => 3,
_ => throw new System.NotImplementedException(),
MyEnum.FizzBuzz => throw new System.NotImplementedException(),
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@Youssef1313
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Member Author

@CyrusNajmabadi Anything left to merge?

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

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 modified the milestones: Next, 16.10.P2 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