You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are things we used to support, but which became unsupported in the rewrite in #56932
Casting enum to int to perform bitwise negation. Added in 4828941.
Unnecessary nullable cast in a constant pattern. For example: This is actually not a case to remove. These patterns are not legal.
voidMain(int?n){varv=nis[|(int?)|]0;}
This is currently broken because GetOperation on the (int?)0 currently returns null. Possibly a compiler bug.
Nullable casts in constant patterns. For example: This is actually not a case to remove. These patterns are not legal.
int?nullable;returnnullableis(int?)1 or (int?)2
Widening cast in 'is' expression. Fixed in 065873a.
Comparison of an enum value against constant 0 directly. Added in 7b73cbf.
Widening cast in 'is' expression. Added in 065873a.
Conditional expressions where removing the cast does change the value of of the conditional. But it is not noticeable because of an outer implicit conversion. For example: Fixed in Fix cast simplification issues #57066
long f1 = (b == 5) ? 4 : [|(long)|]5
Here, removing the (long) cast makes the condition no return an Int32 value instead of an Int64. However, this code, the Int32 would get widened to an Int64 anyways. So the cast can be removed.
Extending the signed value here doesn't need to happen prior to the bitwise negation. THe negation can happen here, and the sign extension that occurs afterwards as part of the binary operation will result in the same value.
Cast to a different (but compatible) delegate type inside a delegate constructor. For example:
Removing this cast is fine. While it change the type of 'y' from 'object' to 'string'. However, that has no impact on how the lambda executes (As it does not use 'y').
Chained nullable casts that don't impact the final result. For example:
These are things we used to support, but which became unsupported in the rewrite in #56932
Casting enum to int to perform bitwise negation.Added in 4828941.Unnecessary nullable cast in a constant pattern. For example:This is actually not a case to remove. These patterns are not legal.This is currently broken because
GetOperationon the(int?)0currently returnsnull. Possibly a compiler bug.Nullable casts in constant patterns. For example:This is actually not a case to remove. These patterns are not legal.Widening cast in 'is' expression.Fixed in 065873a.Comparison of an enum value against constant 0 directly.Added in 7b73cbf.Widening cast in 'is' expression.Added in 065873a.Conditional expressions where removing the cast does change the value of of the conditional. But it is not noticeable because of an outer implicit conversion. For example:Fixed in Fix cast simplification issues #57066long f1 = (b == 5) ? 4 : [|(long)|]5Here, removing the
(long)cast makes the condition no return an Int32 value instead of an Int64. However, this code, the Int32 would get widened to an Int64 anyways. So the cast can be removed.Similarly:
int? y = x ? [|(int?)|]1 : 0;Sign extension prior to a bitwise negation. For example:Fixed in Fix cast simplification issues #57066Extending the signed value here doesn't need to happen prior to the bitwise negation. THe negation can happen here, and the sign extension that occurs afterwards as part of the binary operation will result in the same value.
Cast to a different (but compatible) delegate type inside a delegate constructor. For example:
This cast can be removed safely.
Unnecessary cast in a
goto caseclause. For example:This is currently broken because
GetOperationon the(long)5currently returnsnull. Possibly a compiler bug.Cast in a foreach from a string/array to IENumerable. For example:
removing this cast will change runtime behavior, but not in an observable fashion.
Comparing a nullable to null, versus casting it to a reference type and comparing to null. For example:
Some casts in foreach-statements can be removed. For example:
Removing the cast causes this to have an IEnumerable conversion, not an IEnumerable conversion. But this should be allowed.
Complex lambda cases where the parameter type would change, but it would have no impact on the body code. For example:
Removing this cast is fine. While it change the type of 'y' from 'object' to 'string'. However, that has no impact on how the lambda executes (As it does not use 'y').
Chained nullable casts that don't impact the final result. For example:
Console.WriteLine((int)(float?)(int?)2147483647);Co/contravariance with delegates. For example: