#330: Good code is red

bool x = true;

switch (_x_)
{
case true: break;
case false: break;
}

it says "Value of integral type expected"

7 comments
Comment actions Permalink

Nat

I don't have a fix for you but shouldn't you just be using:

if (x) {
//
}
else {
//
}


instead of the switch statement?

Perhaps the guys at JetBrains never considered using a bool in a switch
so they did not include it as an allowed type.

In article <5070223.1170773115841.JavaMail.itn@is.intellij.net>,
no_reply@jetbrains.com says...

bool x = true;

switch (_x_)
{
case true: break;
case false: break;
}

it says "Value of integral type expected"

0
Comment actions Permalink

I know. I didn't write that piece of code though :)

0
Comment actions Permalink

Hello Nat,

unlilke C and C++ boolean are not integral types in C#

bool x = true;

switch (_x_)
{
case true: break;
case false: break;
}
it says "Value of integral type expected"



0
Comment actions Permalink

But C# can compile this code. I'm just saying that R# should not error out anything that C# compiler can compile.

0
Comment actions Permalink

Hello,

We appreciate your feedback.

The corresponding JIRA request has been created, and you are welcome to monitor
its status at http://www.jetbrains.net/jira/browse/RSRP-36019.

Best regards,
- Development Team.


0
Comment actions Permalink

bool as governing type of switch statement is directly prohibited by C#
specification.
There are a number of cases when Microsoft C# compiler behavour differs from
specification.

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Nat" <no_reply@jetbrains.com> wrote in message
news:5070223.1170773115841.JavaMail.itn@is.intellij.net...

bool x = true;

>

switch (_x_)
{
case true: break;
case false: break;
}

>

it says "Value of integral type expected"



0
Comment actions Permalink

Moreover, there are non-evident reasons why bool is prohibited. Hint - how
op_True and op_False operators should be treated? And what should be done if
they do not match boolean logic?

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:erh0o1$hum$1@is.intellij.net...

bool as governing type of switch statement is directly prohibited by C#
specification.
There are a number of cases when Microsoft C# compiler behavour differs
from specification.

>

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Nat" <no_reply@jetbrains.com> wrote in message
news:5070223.1170773115841.JavaMail.itn@is.intellij.net...

>> bool x = true;
>>
>> switch (_x_)
>> {
>> case true: break;
>> case false: break;
>> }
>>
>> it says "Value of integral type expected"
>



0

Please sign in to leave a comment.