Object Variable Not Set

Warns about assignments that appear to be assigning an object reference without the 'Set' keyword.

Reasoning

Omitting the 'Set' keyword will Let-coerce the right-hand side (RHS) of the assignment expression. If the RHS is an object variable, then the assignment is implicitly assigning to that object's default member, which may raise run-time error 91 at run-time.

Default severity

Error

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething() Dim foo As Object foo = New Collection ' ... End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething() Dim foo As Object Set foo = New Collection ' ... End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.ObjectVariableNotSetInspection.cs (Prerelease-v2.5.9.6289)