Examples of errors detected by the V3137 diagnostic


V3137. The variable is assigned but is not used by the end of the function.


Roslyn Analyzers

V3137 The 'sourceOrigins' variable is assigned but is not used by the end of the function. TaintedDataAnalysis.TaintedDataOperationVisitor.cs 328


public override TaintedDataAbstractValue VisitArrayInitializer(
  IArrayInitializerOperation operation,
  object argument)
{
  HashSet<SymbolAccess> sourceOrigins = null;
  ....
  if (baseAbstractValue.Kind == TaintedDataAbstractValueKind.Tainted)
  {
     sourceOrigins = new HashSet<SymbolAccess>(....);
  }
  ....
}

Azure PowerShell

V3137 The 'apiVersionSetId' variable is assigned but is not used by the end of the function. GetAzureApiManagementApiVersionSet.cs 69


public String ApiVersionSetId { get; set; }
....
public override void ExecuteApiManagementCmdlet()
{
  ....
  string apiVersionSetId;

  if (ParameterSetName.Equals(ContextParameterSet))
  {
    ....
    apiVersionSetId = ApiVersionSetId;
  }
  else
  {
    apiVersionSetId = ....;
  }

  if (string.IsNullOrEmpty(ApiVersionSetId))  // <=
  {
    WriteObject(....);
  }
  else
  {
    WriteObject(Client.GetApiVersionSet(...., ApiVersionSetId))  // <=
  }
}

Similar errors can be found in some other places:

  • V3137 The 'cacheId' variable is assigned but is not used by the end of the function. RemoveAzureApiManagementCache.cs 94

Telerik UI for UWP

V3137 The 'leftMargin' variable is assigned but is not used by the end of the function. DragDrop.cs 87


internal static void StartDrag(....)
{
  ....
  if (frameworkElementSource != null)
  {
    leftMargin = frameworkElementSource.Margin.Left;    // <=
    topMargin = frameworkElementSource.Margin.Top;      // <=
  }
  if (dragDropElement == null ||
     !dragDropElement.CanStartDrag(trigger, initializeContext))
  {
    return;
  }

  var context = dragDropElement
               .DragStarting(trigger, initializeContext);

  if (context == null)
  {
    return;
  }

  var startDragPosition = e.GetCurrentPoint(context.DragSurface.RootElement)
                           .Position;
  var relativeStartDragPosition = e.GetCurrentPoint(uiDragDropElement)
                                   .Position;
  var dragPositionMode = DragDrop.GetDragPositionMode(uiDragDropElement);

  AddOperation(new DragDropOperation(context,
                                     dragDropElement,
                                     dragPositionMode,
                                     e.Pointer,
                                     startDragPosition,
                                     relativeStartDragPosition));
}

Similar errors can be found in some other places:

  • V3137 The 'topMargin' variable is assigned but is not used by the end of the function. DragDrop.cs 88
  • V3137 The 'currentColumnLength' variable is assigned but is not used by the end of the function. WrapLayout.cs 824


Bugs Found

Checked Projects
363
Collected Errors
13 495