5.6.10 Simple Name Expressions

A simple name expression consists of a single identifier with no qualification or argument list.

 simple-name-expression = name 

Static semantics. Simple name expressions are resolved and classified by matching <name> against a set of namespace tiers in order.

The first tier where the name value of <name> matches the name value of at least one element of the tier is the selected tier. The match that the simple name expression references is chosen as follows:

§ If the selected tier contains matches from multiple referenced projects, the matches from the project that has the highest reference precedence are retained and all others are discarded.

§ If both an Enum type match and an Enum member match are found within the selected tier, the match that is defined later in the module is discarded. In the case where an Enum member match is defined within the body of an Enum type match, the Enum member match is considered to be defined later in the module.

§ If there is a single match remaining in the selected tier, that match is chosen.

§ If there are 2 or more matches remaining in the selected tier, the simple name expression is invalid.

If all tiers have no matches, unless otherwise specified, the simple name expression is invalid.

If <name> specifies a type character, and this type character’s associated type does not match the declared type of the match, the simple name expression is invalid.

The simple name expression refers to the chosen match, inheriting the declared type, if any, from the match.

Simple name expressions are classified based on the entity they match:

Match

Simple Name Expression Classification

Constant or Enum member

Value expression

Variable, including implicitly-defined variables

Variable expression

Property

Property expression

Function

Function expression

Subroutine

Subroutine expression

Project

Project expression

Procedural module

Procedural module expression

Class module, UDT or Enum type

Type expression

 

The namespace tiers under the default binding context are as follows, in order of precedence:

§ Procedure namespace: A local variable, reference parameter binding or constant whose implicit or explicit definition precedes this expression in an enclosing procedure.

§ Enclosing Module namespace: A variable, constant, Enum type, Enum member, property, function or subroutine defined at the module-level in the enclosing module.

§ Enclosing Project namespace: The enclosing project itself, a referenced project, or a procedural module contained in the enclosing project.

§ Other Procedural Module in Enclosing Project namespace: An accessible variable, constant, Enum type, Enum member, property, function or subroutine defined in a procedural module within the enclosing project other than the enclosing module.

§ Referenced Project namespace: An accessible procedural module contained in a referenced project.

§ Module in Referenced Project namespace: An accessible variable, constant, Enum type, Enum member, property, function or subroutine defined in a procedural module or as a member of the default instance of a global class module within a referenced project.

There is a special exception to these namespace tiers when the match has the name value "Left":

§ If the match has the name value "Left", references a function or subroutine that has no parameters, or a property with a Property Get that has no parameters, the declared type of the match is any type except a specific class, Object or Variant, and this simple name expression is the <l-expression> within an index expression with an argument list containing 2 arguments, discard the match and continue searching for a match on lower tiers.

Under the default binding context, if all tiers have no matches:

§ If the variable declaration mode for the enclosing module is explicit-mode, the simple name expression is invalid.

§ Otherwise, if the variable declaration mode for the enclosing module is implicit-mode, a new local variable is implicitly declared in the current procedure as if by a local variable declaration statement immediately preceding this statement with a <variable-declaration-list> containing a single <variable-dcl> element consisting of the text of <name>. This newly created variable is the match.

The namespace tiers under the type binding context are as follows, in order of precedence:

§ Enclosing Module namespace: A UDT or Enum type defined at the module-level in the enclosing module.

§ Enclosing Project namespace: The enclosing project itself, a referenced project, or a procedural module or class module contained in the enclosing project.

§ Other Module in Enclosing Project namespace: An accessible UDT or Enum type defined in a procedural module or class module within the enclosing project other than the enclosing module.

§ Referenced Project namespace: An accessible procedural module or class module contained in a referenced project.

§ Module in Referenced Project namespace: An accessible UDT or Enum type defined in a procedural module or class module within a referenced project.

The namespace tiers under the procedure pointer binding context are as follows, in order of precedence:

§ Enclosing Module namespace: A function, subroutine or property with a Property Get defined at the module-level in the enclosing module.

§ Enclosing Project namespace: The enclosing project itself or a procedural module contained in the enclosing project.

§ Other Procedural Module in Enclosing Project namespace: An accessible function, subroutine or property with a Property Get defined in a procedural module within the enclosing project other than the enclosing module.

The namespace tiers under the conditional compilation binding context are as follows, in order of precedence:

§ Enclosing Module namespace: A conditional compilation constant defined at the module-level in the enclosing module.

§ Enclosing Project namespace: A conditional compilation constant defined in an implementation-defined way by the enclosing project itself.