Undeclared Variable

Warns about implicit local variables that are used but never declared.

Reasoning

If this code compiles, then Option Explicit is omitted and compile-time validation is easily forfeited, even accidentally (e.g. typos).

Default severity

Error

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething() foo = 42 ' foo is not declared ' ... End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething() Dim foo As Long foo = 42 ' ... End Sub

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