Examples of errors detected by the V3012 diagnostic.


V3012. The '?:' operator, regardless of its conditional expression, always returns one and the same value.


MonoDevelop

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: WindowCommands.NextDocument. MonoDevelop.Ide WindowCommands.cs 254


public enum WindowCommands
{
  NextDocument,
  PrevDocument,
  OpenDocumentList,
  OpenWindowList,
  SplitWindowVertically,
  SplitWindowHorizontally,
  UnsplitWindow,
  SwitchSplitWindow,
  SwitchNextDocument,
  SwitchPreviousDocument
}

protected static void Switch (bool next)
{
  if (!IdeApp.Preferences.EnableDocumentSwitchDialog) {
       IdeApp.CommandService.DispatchCommand (
         next ? WindowCommands.NextDocument :
                WindowCommands.NextDocument);
       return;
  }

  var toplevel = Window.ListToplevels ()
                       .FirstOrDefault (w => w.HasToplevelFocus)
                       ?? IdeApp.Workbench.RootWindow;
  var sw = new DocumentSwitcher (toplevel, next);
  sw.Present ();
}

MonoDevelop

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: result.Test.FullName. GuiUnit_NET_4_5 NUnit2XmlOutputWriter.cs 207


private void StartTestElement(ITestResult result)
{
  ITest test = result.Test;
  TestSuite suite = test as TestSuite;

  if (suite != null)
  {
    xmlWriter.WriteStartElement("test-suite");
    xmlWriter.WriteAttributeString("type", suite.TestType);
    xmlWriter.WriteAttributeString("name",
      suite.TestType == "Assembly" ?
        result.Test.FullName : result.Test.FullName);
  }
  ....
}

IronPython and IronRuby

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: newHandlers. DebugInfoRewriter.cs 252


protected override MSAst.Expression VisitTry(
  MSAst.TryExpression node) {
  ....
  if (newHandlers != null || newFinally != null) {
    node = Ast.MakeTry(node.Type, node.Body,
      newFinally != null ? newFinally : node.Finally,
      node.Fault,
      newHandlers != null ? newHandlers : newHandlers
    );
  }
  return node;
}

.NET Compiler Platform ("Roslyn")

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value. AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs 177


private Task<SyntaxToken>
GetNewTokenWithRemovedOrToggledPragmaAsync(....)
{
  var result = isStartToken
    ? GetNewTokenWithPragmaUnsuppress(
        token, indexOfTriviaToRemoveOrToggle, _diagnostic, Fixer,
        isStartToken, toggle)
    : GetNewTokenWithPragmaUnsuppress(
        token, indexOfTriviaToRemoveOrToggle, _diagnostic, Fixer,
        isStartToken, toggle);

  return Task.FromResult(result);
}

.NET Compiler Platform ("Roslyn")

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: ScriptingResources.PlusAdditionalError. CommandLineRunner.cs 428


private void DisplayDiagnostics(....)
{
  ....
  _console.Out.WriteLine(
    string.Format((notShown == 1) ?
      ScriptingResources.PlusAdditionalError :
      ScriptingResources.PlusAdditionalError,
      notShown));
  ....
}

Mono

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: Color.FromArgb (150, 179, 225). ProfessionalColorTable.cs 258


private void CalculateColors ()
{
  ....
  button_pressed_highlight = use_system_colors ?
                             Color.FromArgb (150, 179, 225) :
                             Color.FromArgb (150, 179, 225);
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;
On our website we use a cookie to collect information of a technical nature.
If you do not agree, please leave the site. Learn More →
Do not show again