Table of Contents

RDC00208: Shadowed declaration

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

A declaration has the name of something else its code would see by that name:

  • a local variable, a local constant or a parameter, named like a variable, a constant or a procedure of the module, a Public member of another module, a member of an enumeration, a function of a library, or a module;
  • a variable, a constant, a procedure or a property of the module, named like a Public member of another module, a member of a library, or, in a document module, a member of its host's class (Range in a worksheet's module).

A simple name is first matched in its procedure, then in its module, then in the project and the libraries it references (MS-VBAL §5.6.10). Dim Left As String makes Left(s, 1) an index of the variable rather than the function of the library; a parameter named Count is not the module's Count; a module's Public Function Replace is what Replace calls in the project, in place of VBA.Strings.Replace. The code compiles, and does what the declarations say, which is not always what the reader takes it to say. A name of its own says it plainly.

What the name would mean without the declaration is the environment host's to say, since it resolves names across modules and libraries: it is a fact of the declaration (DeclarationFact.Hides).

How it is raised

Situation Example Resolution
A local named like a variable of the module. Private Count As Long … Dim Count As Long Rename the local (Dim itemCount As Long), or use the module's variable.
A parameter named like a function of the library. Sub Report(ByVal Date As Date) Rename the parameter (ByVal reportDate As Date).
A local named like a Public member of another module. Dim Total As Long, where Module2 declares Public Total As Long Rename the local.
A local named like a member of an enumeration. Dim Red As Long, where an enumeration declares Red Rename the local.
A function of the module named like a function of the library. Public Function Replace(ByVal s As String) As String Rename the function (ReplaceTabs), or call the library's as VBA.Replace.
A variable of the module named like a Public member of another module. Private Total As Long, where Module2 declares Public Total As Long Rename the variable.

A Private member of another module is not seen by the module, and is not hidden. Nor is a local of another procedure.

See also


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