My mistake in "if(a,b,c)", "switch(a,b,c)" is not rejected by the compiler

Typos do happen all the time. By mistake, recently I typed
if (a, b, c) doSomething
and
switch (a, b, c) {
some case statements
}
The compiler (IDE 1.8.19) did accept this without any warning or error message. It seems like only variable c is evaluated.
When I realized my mis-typing I was more than surprised not to get an error message. I must confess I never wrote a parser, but I think that task should be redone some time.

It is valid code.

1 Like

How about using code tags to provide your exact code in context? Thanks
C

Enable ALL compile warnings in File, Preferences and try those statements again. You will see that the compiler does not like it but will let you do it anyway.

1 Like

We'll have to wait for the Google sentient compiler that is coming to know how the compiler really feels. :expressionless:

Many times warnings are pointing out something you really should fix.

Some warnings, like the one issued in this case (which surprises me that it does) are pointing out something that is valid but maybe perhaps not what you meant, the classic examp,e woukd be using = where == would be more commonly seen.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.