Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Inspection for redundant variable initializations #2732
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
Does that conflict with another inspection?
could raise the inspection "foo may not be assigned a value"
could raise "foo is referenced before being assigned a value"
I may be misremembering some similar inspection in another parser.