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

'Remove unnecessary cast' adds unnecessary parentheses #25554

Closed
Neme12 opened this issue Mar 17, 2018 · 10 comments
Closed

'Remove unnecessary cast' adds unnecessary parentheses #25554

Neme12 opened this issue Mar 17, 2018 · 10 comments
Assignees
Milestone

Comments

@Neme12
Copy link
Contributor

Neme12 commented Mar 17, 2018

Inside a switch case:

switch (true)
{
    case (bool)default(bool):
}
switch (true)
{
    case (default(bool)):
}

inside a when clause:

switch (true)
{
    case true when (bool)default(bool):
}
switch (true)
{
    case true when (default(bool)):
}

inside an is pattern expression:

if (true is (bool)default(bool)) ;
if (true is (default(bool))) ;

Tagging @CyrusNajmabadi who's working on a code fix specifically to remove unnecessary parentheses. The problem is inside ParenthesizedExpressionSyntaxExtensions.CanRemoveParentheses. The first two cases should be trivial to fix but that's not the case inside is, where associativity plays a role. For example it's important to add tests so that parentheses are not removed here:

if (true is (true == true)) ;
@CyrusNajmabadi
Copy link
Member

The first two cases should be trivial to fix but that's not the case inside is, where associativity plays a role. For example it's important to add tests so that parentheses are not removed here:

This should already be checked in my PR. precedence is different here, so we would consider those parens necessary.

@CyrusNajmabadi
Copy link
Member

Tagging @CyrusNajmabadi who's working on a code fix specifically to remove unnecessary parentheses. The problem is inside ParenthesizedExpressionSyntaxExtensions.CanRemoveParentheses. The first two cases should be trivial to fix

I can do this if you'd like. But i don't want to step on your toes if you wanted to take this.

@Neme12
Copy link
Contributor Author

Neme12 commented Mar 17, 2018

I was going to go after this but then realized you might have fixed the issue inside is to take care of precedence since you changed a lot in that method. I'd prefer if you took care of this and added tests for these cases to tests for your analyzer and not to 'Remove unnecessary cast', since you can cover all of the cases in there.

@Neme12
Copy link
Contributor Author

Neme12 commented Mar 17, 2018

So if I was going to do this I would potentially have to duplicate some of your logic and step on your toes.

@Neme12
Copy link
Contributor Author

Neme12 commented Mar 17, 2018

A fix for this will break a few tests I added though: #25538 (comment) that currently expect these extra parens. Depending on which PR gets merged first, soebody will have to take care of that later.

But as I sad I'd be happy if you fixed this because your PR has a lot more to do with unnecessary parentheses than mine does.

@CyrusNajmabadi
Copy link
Member

No prob. I'll make the change. Whoever goes in second will just do the fixup.

@CyrusNajmabadi
Copy link
Member

@Neme12 Have made the changes here: #21316 Want to take a look?

@jcouv jcouv added the Area-IDE label Mar 18, 2018
@jinujoseph jinujoseph added this to the 15.8 milestone Apr 1, 2018
@jinujoseph jinujoseph added Feature Request 4 - In Review A fix for the issue is submitted for review. labels Apr 1, 2018
@Neme12
Copy link
Contributor Author

Neme12 commented Apr 4, 2018

@CyrusNajmabadi My PR was merged so you might want to fix some of those tests in your branch. Thanks for fixing this.

@CyrusNajmabadi
Copy link
Member

Thanks!

@Neme12
Copy link
Contributor Author

Neme12 commented Jun 4, 2018

This is fixed in 15.8 preview 2. @CyrusNajmabadi I think you fixed this with #26523 right?
@jinujoseph This can be closed

@jinujoseph jinujoseph removed the 4 - In Review A fix for the issue is submitted for review. label Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants