2.6.2 Semantic Compilation Errors
A semantic compilation error is raised by the static semantics layer while walking the abstract syntax tree (AST) with symbol information. Examples are a duplicate declaration, an undefined name, and a type mismatch in a constant expression.
| Code family | VBC, range VBC09300–VBC09999 |
| Title | Compile error |
| Raised by | the static semantics layer (abstract syntax tree) |
| Source metadata | VBCompileErrorInfo |
| Severity | Error |
| Detail | the offending symbol / expression, on Diagnostic.data |
Numeric Range
VBCompileErrorId reserves the range [9300..] for semantic compilation errors: errors issued from the static semantics analysis pass report a value greater than or equal to 9300. MS-VBAL does not distinguish a compile-time error raised in CST semantics from one raised in AST semantics; RDCore splits syntax errors and semantic compilation errors by numeric range only.
Compilation errors issued from a language core extension report a VBCompileErrorId value between 8000 and 9299; see RD-VBAL §1.1.4 Core Diagnostics.
Emission
Semantic compilation errors are emitted by the resolver and the static semantic pass.
ICoreDiagnosticsFactory.FromVBCompileError is the projection for semantic compilation errors, the counterpart of FromVBSyntaxError, and SemanticContextBuilder.AddDiagnosticOnError uses it. No production code path calls AddDiagnosticOnError, so semantic compilation errors are not currently projected to LSP diagnostics.
Note
Not implemented. The RDCore.Diagnostics handler for rdcore/diagnostics/document projects the syntax errors of the parse result only. Semantic compilation errors do not reach the textDocument/diagnostic pull through it; see RD-VBAL §2.6.5 Diagnostics Pipeline.
Published Codes
| Code | Title | Condition |
|---|---|---|
VBC09309 |
Label not defined | a jump names a line label or line number the procedure does not define |
VBC09312 |
Exit Do not within Do...Loop | an Exit Do statement is not lexically inside a Do loop |
VBC09313 |
Exit For not within For...Next | an Exit For statement is not lexically inside a For or For Each loop |
VBC09314 |
Exit Function not allowed in Sub or Property | an Exit Function statement is in a Sub, or in a Property Let or Property Set (it is accepted in a Property Get, as MS-VBA does) |
VBC09315 |
Exit Property not allowed in Sub or Function | an Exit Property statement is in a Sub or a Function |
VBC09319 |
Duplicate label definition | a procedure defines the same line label or line number more than once |
VBC09320 |
Inconsistent property accessors | a property's Get/Let/Set sharing a name do not together describe one valid property |
VBC09321 |
Argument required for Property Let or Property Set | a Property Let or Property Set declares no parameters at all |
VBC09322 |
Event not defined | a RaiseEvent names an event the class module it is written in does not declare |
VBC09323 |
Wrong number of arguments or invalid argument for event | a RaiseEvent's arguments are not compatible with the parameter list of its event |
VBC09324 |
Invalid type for WithEvents variable | a WithEvents variable is not declared as a specific class that has an event, or is declared as the class of its own module |
VBC09325 |
Invalid event name | the name of an Event declaration contains an underscore |
VBC09326 |
Invalid event handler | a procedure named for a WithEvents variable and an event of its class is not a subroutine, or has a parameter list incompatible with the event's |
VBC09327 |
ByVal argument not allowed here | an argument is written with ByVal in an argument list that is not that of an invocation of an external procedure |
VBC09328 |
Invalid Implements directive | an Implements directive names the class itself, a class another directive names, a class with an underscore in a public member, or an interface whose prefix begins another's |
VBC09329 |
Object module needs to implement all members of its interface | a public variable or method of an interface class has no implemented name declaration |
VBC09330 |
Invalid implemented member | an implemented name declaration is not the kind of declaration its member is, or its parameters or type are not equivalent |
VBC09331 |
Sub or Function not defined | a statement the language the code is written in does not have: a bare Print outside the platform's BASIC |
VBC09332 |
Exit Sub not allowed in Function or Property | an Exit Sub statement is in a Function or a property |
VBC09333 |
Variable required | an expression that is certainly not a variable (a literal, an operator's result, a constant) is the target of a Mid statement, or the variable a Line Input #, Input # or Get reads into |
VBC09334 |
Access not valid for the file mode | the Access clause of an Open statement is not one its For mode allows |
Instruction-list lowering reports VBC09309 for a Jump/JumpTable label operand that does not resolve, and VBC09319 for a repeated label definition; see RD-VBAL §3.5.3 Lowering Block Statements. VBC09320 and VBC09321 are raised by ScopeTreeSymbolResolver; see RD-VBAL §2.3.1.3 Name Resolution. VBC09322 and VBC09323 are raised by StatementStaticSemanticsEvaluator; see RD-VBAL §5.4.2.20 RaiseEvent Statement. VBC09324, VBC09325 and VBC09326, and a repeated event name as VBC09303, are raised by ClassModuleEventSemantics, which checks what a class module declares about events; see RD-VBAL §5.2.4.3, §5.2.3.1.2 and §5.3.1.8. VBC09327 is raised by ExpressionStaticSemanticsEvaluator; see RD-VBAL §5.6.13.1 Argument Lists. VBC09328, VBC09329 and VBC09330, and VBC09311 for an interface class that does not exist, are raised by ImplementsSemantics; see RD-VBAL §5.2.4.2 and §5.3.1.9.
Other Compilation Errors
This specification refers to the following semantic compilation errors on other pages.
| Code | VBCompileErrorId |
Condition | See |
|---|---|---|---|
VBC09301 |
AmbiguousName |
A name resolves in more than one enclosing scope (members promoted from different modules or references). The reference must qualify the name. | RD-VBAL §2.3.1.3 Name Resolution |
VBC09302 |
VariableNotDefined |
An unresolved simple name. The static-semantics layer consumes the module's ModuleDirectives to decide whether such a name is a deferred VBUnknownType or this error. |
RD-VBAL §2.3.1.3 Name Resolution |
VBC09303 |
DuplicateDeclaration |
A name is declared more than once within one module or procedure. | RD-VBAL §2.3.1.3 Name Resolution |
VBC09304 |
InvalidUseOfObject |
Set Widget = New Widget or Set Widget = Nothing, for a predeclared class Widget. |
RD-VBAL §3.1.1 Attributes |
VBC09311 |
UserDefinedTypeNotDefined |
An unknown type should raise this error; verbose diagnostic messages should help clarify its meaning. | RD-VBAL §2.4.2 Non-intrinsic Types |
An appropriate compile-time error should be issued for a duplicate declaration and for an ambiguous name. The symbol resolver reports the error kind; the caller, which knows where the reference is, builds the located diagnostic.
⏮️ RD-VBAL §2.6.1 Syntax Errors | ⏭️ RD-VBAL §2.6.3 Runtime Errors