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)) ;
Inside a switch case:
inside a when clause:
inside an is pattern expression:
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 insideis, where associativity plays a role. For example it's important to add tests so that parentheses are not removed here: