Current filter:
                                You should refresh the page.
                                  • It seems to me, that CR reports a CRR0012 ("Logical OR expression has opposite operands") when it's not appropriate.

                                    [VB.NET]
                                    Module Module1 Sub Main() Check(-1, -1, False) Check(1, 1, False) Check(0, 1, True) Check(0, -1, True) Check(1, -1, True) Check(-1, 1, True) Console.ReadLine() End Sub Sub Check(a As Integer, b As Integer, exp As Boolean) Dim act1 As Boolean = (a = 0) OrElse (a > 0 AndAlso b = -1) OrElse (a = -1 AndAlso b > 0) Dim act2 As Boolean = (a >= 0) AndAlso (a = 0 OrElse b = -1) OrElse (a = -1 AndAlso b > 0) Dim act3 As Boolean = (a = 0) Or (a > 0 And b = -1) Or (a = -1 And b > 0) Dim act4 As Boolean = (a > 0 AndAlso b = -1) OrElse (a = -1 AndAlso b > 0) OrElse (a = 0) Dim equ12 As Boolean = (act1 = act2) Dim equ13 As Boolean = (act1 = act3) Console.WriteLine($"a={a}, b={b}, exp={exp}, act1={act1}, act2={act2}, equ12={equ12}, equ13={equ13}") End Sub End Module

                                    On statement "act1" CR reports CRR0012. Transforming to the suggested equivalent statement "act2" resolves CRR0012. But I'm not sure, if this statement ist more readable!

                                    When changing the statement "act1" to "act3" (OrElse => Or, AndAlso => And) also CRR0012 is resolved. Why the difference between short curcuit or not?!

                                    And in statement "act4" when putting the first comparison from "act1" from the first position to the end also CRR0012 is resolved.

                                • Alex Z (DevExpress) 07.06.2017

                                  Robert,

                                  I think you are right here, it seems that this is a false positive and this diagnostic should not be shown for this code, since a = 0, a = -1, a > 0 are not actually opposites.
                                  That you for your report and sample code, we will improve this for future versions.

                                1 Solution

                                Creation Date Importance Sort by

                                Fixed: