Examples of errors detected by the V3031 diagnostic.


V3031. An excessive check can be simplified. The operator '||' operator is surrounded by opposite expressions 'x' and '!x'.


SharpDevelop

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions. DockablePane.cs 549


internal override ManagedContent RemoveContent(int index)
{
  .....
  if (((dockableContent == null)
      || (dockableContent != null &&
          dockableContent.SavedStateAndPosition == null)
      || (dockableContent != null &&
          dockableContent.SavedStateAndPosition.ContainerPane
          != this))
      && Items.Count == 0)
  ....
}

There is no error here, but the code can be simplified. "dockableContent != null" checks are not necessary here.


Xamarin.Forms

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions. Xamarin.Forms.Platform.iOS.Classic ContextActionCell.cs 102


public override void LayoutSubviews()
{
  ....
  if (_scroller == null || (_scroller != null &&
                            _scroller.Frame == Bounds))
    return;
  ....
}

There is no error here, but the code can be simplified.


FlashDevelop

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions. DockContentHandler.cs 540


internal void SetDockState(....)
{
  ....
  if ((Pane != oldPane) || (Pane == oldPane
    && oldDockState != oldPane.DockState))
  {
    RefreshDockPane(Pane);
  }
  ....
}

There is no error here, however, the conditions Pane != oldPane and Pane == oldPane are mutually exclusive, so this expression can be simplified


Mono

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions. mcs-net_4_x ILGenerator.cs 456


public void Emit(OpCode opc)
{
  Debug.Assert(opc != OpCodes.Ret || (
               opc == OpCodes.Ret && stackHeight <= 1));
  ....
}

There is no error here, but the code can be simplified.


Mono

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions. System.Windows.Forms-net_4_x ContainerControl.cs 506


public bool Validate (bool checkAutoValidate)
{
  if ((checkAutoValidate &&
      (AutoValidate != AutoValidate.Disable)) ||
      !checkAutoValidate)
    return Validate ();

  return true;
}

There is no error here, but the code can be simplified.


Orchard CMS

V3031 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions '!ssl' and 'ssl && CdnSupportsSsl'. ResourceDefinition.cs 190


public string ResolveUrl(....) {
  ....
  if (!ssl || (ssl && CdnSupportsSsl)) {
    ....
  }
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;