Table of Contents

RDC00106 — Implicit Variant declaration

Severity: Information  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: ImplicitVariantDeclarationAnalyzer

A variable or a parameter is declared without a type, and is a Variant.

A declaration with no As clause and no type-declaration character has the implicit type of its name, which is Variant unless a Def<Type> directive covers the name (MS-VBAL §5.2.3.1.5 Implicit Type Determination; RD-VBAL §5.2.2 Implicit Definition Directives). A Variant accepts any value, so nothing the compiler knows catches a value of the wrong type, and a reader cannot tell whether a Variant is deliberate. A classic trap is Dim a, b As Long, where only b is a Long (see RDC00204). The diagnostic is an opinion of the analyzer and not a condition of the language: both are legal VBA.

A name that a Def<Type> directive covers is not a Variant and is not reported here: the directive is (see RDC00103). A constant is not reported either, since its type is the type of its value.

That a declaration states no type is a fact of the way it is written: the analyzer reads it off the syntax tree. It is a suggestion because As Variant does not change what the declaration is.

How it is raised

Situation Example Resolution
A variable of a module or a procedure is declared with no type. Dim total Write the type: Dim total As Long, or As Variant if that is intended.
A parameter is declared with no type. Sub Work(total) Write the type: total As Long, or As Variant if that is intended.

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca