
* Modify rule S1110: Update rule description Improve grammar and sentence structure. * Modify rule S3603: Update rule description Improve grammar in the sentence structure. * Modify rule S3449: Update rule description Clarify the sentence structure with minor word changes. * Modify rule S3449: correct word in description Correct spelling mistakes in two instances of one word.
34 lines
1.6 KiB
Plaintext
34 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Numbers can be shifted with the `<<` and `>>` https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/bit-shift-operators[operators], but the right operand of the operation needs to be an `int` or a type that has an https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions[implicit conversion] to `int`. However, when the left operand is an `object`, the compiler's type checking is turned off, therfore you can pass anything to the right of a shift operator and have it compile. If the argument can't be implicitly converted to `int` at runtime, a https://learn.microsoft.com/en-us/dotnet/api/microsoft.csharp.runtimebinder.runtimebinderexception[RuntimeBinderException] will be raised.
|
|
|
|
[source,vbnet]
|
|
----
|
|
Dim o As Object = 5
|
|
Dim x As Integer = 5
|
|
|
|
x = o >> 5 ' Noncompliant
|
|
x = x << o ' Noncompliant
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
This rule does not raise when the left or the right expression is https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing[Nothing].
|
|
|
|
|
|
[source,vbnet]
|
|
----
|
|
x = Nothing >> 5
|
|
x = 5 << Nothing
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/bit-shift-operators[Bit Shift Operators]
|
|
* https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions[Implicit and Explicit Conversions]
|
|
* https://learn.microsoft.com/en-us/dotnet/api/microsoft.csharp.runtimebinder.runtimebinderexception[RuntimeBinderException Class]
|
|
|
|
include::../rspecator-dotnet.adoc[]
|