RDC11015 — Object with no default member used as a value
Severity: Warning · Family: RDC (Rubberduck Core analyzers) ·
Raised by: ValueOfObjectWithNoDefaultMemberAnalyzer
An object of a class that has no default member is where a value is expected: assigned with Let to a variable of a value type or to a Variant, an
operand of an operator other than Is, or an argument of a parameter declared with a value type (ByVal x As Long, CInt, the Limit of Split).
The object has no value to give. VBA compiles the code, and raises a run-time error when it runs:
- error 438 (Object doesn't support this property or method) when the variable holds an object;
- error 91 (Object variable or With block variable not set) when it holds
Nothing.
So, with o declared As Plain, a class with no default member, c = o, c = CInt(o) and Split("a,b,c", ",", o) all raise one of those errors,
every time they run.
This is what Microsoft Office VBA does. The language specification says otherwise: MS-VBAL §5.5.1.1 makes a class with no accessible default member invalid to Let-coerce, which is a compile error (Type mismatch). RD-VBA runs the code as VBA does, and this warning stands in for that compile error.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
| A member of the object is meant. | n = widget, meaning its count |
Read the member: n = widget.Count. |
The object itself is meant, kept in a Variant. |
v = widget |
Set it: Set v = widget. |
| The object is compared with another object. | If a = b Then |
Compare the references: If a Is b Then. |
See also
- RD-VBAL §2.6.4 Rubberduck Core Diagnostics
- RD-VBAL §5.5.1.1 Static Semantics
VBC09310: Type mismatchRDC11012: aSetof a call that always fails
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca