This is based on this question, which seems to me a language glitch or a missing warning in the compiler. My reasoning is that is
will always return true
in expressions of the following type:
int i;
if (i is var j) ....
Taking it a step further, consider the following code:
int i;
if (i is int) .... //Compiler warning: The given expression is always
//of the provided ('int') type.
But, same as with var
, if you do:
if (i is int j) ...
else ...
You won't get any warning (neither given expression is always true
or unreachable code detected in the else
clause) to what, essentially, is the same behavior.
This makes me consider if maybe my initial reasoning is wrong. Is there a some obscure use/corner case I'm missing where this really makes a difference? And if not, is the missing warning and the inconsistent behavior an oversight (or even bug) in the compiler?
The 2022 C-Class sedan starts at $43,550. The midtier Exclusive model starts at $45,800, and the top Pinnacle trim has a starting MSRP of $47,500. All-wheel drive is available in all models for an additional $2,000.
Mercedes-Benz's entry-level sports sedan has been thoroughly redesigned for the 2022 model year but the C-class sticks with its winning formula of luxury and prestige at an affordable price. The modernization gives the C-class what it needs to better battle rivals such as the Audi A4, BMW 3-series, and Genesis G70.
A super duper car with full of comfort with excellent steering. The Mercedes benz ranks 4 out of 20 in luxury cars.
Mercedes-Benz C Class C180 AMG Line 4dr Auto Reviews 2022 | Top Gear.
I believe this is by design, referencing the roslyn source code, starting here: Binder_Operators, Line 2848
Because the heuristic presented here is used to change codegen, it must be conservative. It is acceptable for us to fail to report a warning in cases where humans could logically deduce that the operator will always return [true]. It is not acceptable to inaccurately warn that the operator will always return [true] if there are cases where it might [fail].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With