VBC09320 — Inconsistent property accessors
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A module's Property Get, Property Let, and Property Set sharing a name do not together describe one
valid property
(MS-VBAL §5.3.1.7 Property Declarations).
This code is raised where the accessors are resolved as a group, by
ScopeTreeSymbolResolver, as soon as more
than one accessor exists and any of the conditions below holds. A Property Let/Set with no parameters
at all is checked separately, ahead of this code: see VBC09321.
The verbose detail lists the colliding accessor declarations.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
Two accessors' index-parameter lists differ in count, name, declared type, or ByRef/ByVal mechanism. |
Property Get Foo(i As Integer) next to Property Let Foo(j As Long, v As Integer) |
Give every accessor of the property identical index parameters. |
An index parameter is Optional or a ParamArray, and the property has more than one accessor. |
Property Get Foo(Optional i As Integer) next to Property Let Foo(i As Integer, v As Integer) |
Either drop Optional/ParamArray from the index, or make the property Get-only. |
Property Let and Property Get sharing a name declare a different value type. |
Property Get Foo() As Long next to Property Let Foo(v As String) |
Give the Let accessor's value parameter the same declared type as the Get accessor's return type. |
Property Set's value parameter is not Object, Variant, or a named class. |
Property Set Foo(v As Long) |
Type the value parameter Object, Variant, or a class. |
Notes
An implicit and an explicit ByRef on a corresponding index parameter are not a difference: only the
ByRef-versus-ByVal mechanism is compared, as the exception in MS-VBAL §5.3.1.7 for that case specifies.
A single accessor (a Get-only or Let-only property) has nothing to be inconsistent with, and is never
reported by this code. Optional/ParamArray index parameters are legal only there.
Two corresponding parameters' declared types are compared by the symbol that declares them
(Symbol.SemanticId), not by the type's bare name. A class or user-defined type named Widget in one
module is not the same declared type as a different Widget declared elsewhere, even though the two
share a name.
A declared type that is not resolved (not yet, or not at all) cannot be shown to mismatch anything, so it is deferred rather than flagged. Every other type-comparing static-semantics rule in RDCore follows the same convention.
The VBE bundles all of these conditions into one compile error: "Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter."
The index-parameter-equivalence and Property Set value-type conditions are literal
MS-VBAL §5.3.1.7 static-semantics bullets. The Optional/ParamArray-implies-Get-only
consequence is not stated in the MS-VBAL text, but the wording of the VBE compiler's error confirms it.
See also
- VBC09321 — a
Property Let/Setwith no parameters at all - RD-VBAL §2.6.2 Semantic Compilation Errors
- RD-VBAL §5.3.1.7 Property Declarations
⏮️ VBC09319 Duplicate label definition | ⏭️ VBC09321 Argument required for Property Let or Property Set
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca