Skip to content

Hotfix for Certain "Assignment Not Used" Inspection Results #5045

@ChrisBrackett

Description

@ChrisBrackett

What
If an object instance is created with the New keyword (ex. Set myColl = New Collection) and the variable is later set using a function returning that object type, then the "Assignment Not Used" inspection is triggered.

This sub-type of "Assignment Not Used" could have a hotfix.

In the example below, an instance of the Collection object is created but then overwritten by the next line. The line Set myColl = New Collection is not necessary and can be safely deleted.

Why
Inspection results are good. Hotfixes are better!

Example
This code should trigger the inspection:

Public Sub DoSomething()
    Dim myColl As Collection
    Set myColl = New Collection
    Set myColl = FunctionReturningCollection
End Sub

QuickFixes

  1. Remove object instance creation

    Example code, after quickfix is applied:

Public Sub DoSomething()
    Dim myColl As Collection
    Set myColl = FunctionReturningCollection
End Sub

Resources

  • InspectionNames: ObjectAssignmentNotUsed
  • InspectionInfo: An object instance is created with the New keyword but the object is later set using a method that does not require the object instance to be created in advance.
  • InspectionResults: ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions