Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspection for redundant variable initializations #2732

Open
retailcoder opened this issue Feb 23, 2017 · 1 comment
Open

Inspection for redundant variable initializations #2732

retailcoder opened this issue Feb 23, 2017 · 1 comment
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections

Comments

@retailcoder
Copy link
Member

If a variable's first assignment (taking code paths into account) is a literal with the default value for that variable's declared type, Rubberduck should suggest removing that redundant assignment.

    Dim foo As String
    foo = vbNullString ' or ""

    Dim foo As Integer ' or any numeric type actually
    foo = 0

    Dim foo As Boolean
    foo = False

    Dim foo As Object ' or any reference type
    Set foo = Nothing

    Dim foo As Date
    foo = 0 ' 1899-12-30 12:00:00AM actually, so #1899-12-30#

    Dim foo As Variant
    foo = Empty ' vbEmpty still makes "(foo = vbEmpty)" evaluate to True, but converts to 0
@retailcoder retailcoder added code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. feature-inspections labels Feb 23, 2017
@SystemsModelling
Copy link

SystemsModelling commented Feb 25, 2017

Does that conflict with another inspection?

Dim foo As String
If condition then
    foo="foo"
End If

could raise the inspection "foo may not be assigned a value"

or

Dim foo As Long
For i=1 to 3
    foo=foo + i 
End If

could raise "foo is referenced before being assigned a value"

I may be misremembering some similar inspection in another parser.

@Vogel612 Vogel612 added the enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. label Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Projects
None yet
Development

No branches or pull requests

3 participants