Skip to content

Right Shift Not Number

Integers should be the right operands of shift operators.

What does this mean ?

The << and >> operators can shift numbers, but the right operand of the operation must be an int or a type having an implicit conversion to int. The compiler's type checking is disabled with dynamic, thus you can supply anything to a shift operator and have it build.

What can happen ?

A RuntimeBinderException will be thrown if the argument cannot be converted to an int at runtime.


The operation's right operand must be an int or a type with an implicit conversion to int.

Sample Code

Vulnerable :

dynamic d = 5;
var x = d >> 5.4; // Noncompliant
x = d >> null; // Noncompliant
x <<= new object(); // Noncompliant