Bug Report T533012
Visible to All Users

Code Issues - 'Logical OR expression has opposite operands' false positive

created 8 years ago

It seems to me, that CR reports a CRR0012 ("Logical OR expression has opposite operands") when it's not appropriate.

Visual Basic
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.

Comments (1)
DevExpress Support Team 8 years ago

    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.

    Answers approved by DevExpress Support

    created 8 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.