RDC00208 — Shadowed declaration
Severity: Information · Family: RDC (Rubberduck Core analyzers) ·
Raised by: ShadowedDeclarationAnalyzer
A local variable, a local constant or a parameter has the name of something else the module sees: 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 simple name is first matched in its procedure (MS-VBAL §5.6.10), so in that procedure the name means the
local, and everywhere else it means the other declaration. 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. 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 means in the rest of the module is the environment host's to say, since it resolves names across modules and libraries: it is a fact of the
declaration (DeclarationFact.Hides), what the name resolves to as seen from the module.
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 Private member of another module is not seen by the module, and is not hidden. Nor is a local of another procedure.
See also
- RD-VBAL §2.6.4 Rubberduck Core Diagnostics
- RDC00114 — Implicit array declaration, which a
ReDimof such a name also is
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca