Name look-ups in namespaces and types
Unqualified name look-ups verify the priority hierarchy as follows:
- (1) current namespace/type
- (2) base types (by 'Extends'), ranked from closest to furthest in inheritance hierarchy
- (3) parent namespaces, ranked from closest to furthest in ancestry hierarchy (including global namespace: always furthest in hierarchy)
- (4) imported namespaces (by 'Using'), without hierarchy between them (regardless of their respective level of nesting)
Unqualified names for look-up can be:
- variable names
- procedure names
- type names
- enum names (not their field symbols alone)
a)
If a qualified name with a prefix referring to a namespace is used instead of an unqualified name, the previous rules for unqualified names are amended as follows:
- the look-up begins at the level of the namespace corresponding to the specified prefix (as in (1))
- failing that, then only namespaces imported into this namespace can be candidates for the look-up (as in (4))
- but never the parent namespaces of this namespace nor also the global namespace (not as in (3))
b)
If a qualified name with a prefix ('This' or 'Base') referring to a type is used instead of an unqualified name, the previous rules for unqualified names are amended as follows:
- the look-up begins at the level of the type or base type depending on the specified prefix 'This' or 'Base' (similarly to (1))
- failing that, then only higher base types from closest to furthest can be successively candidates for the look-up (as in (2))
- but never any namespaces, the current also excluded (not as in (3) or (4))
Examples for a):
Code: Select all
Dim Shared As Zstring * 32 duplicate = "..duplicate"
Namespace M
Dim As Zstring * 32 duplicate = "M.duplicate"
Namespace P
End namespace
End Namespace
Namespace N
Using M
End Namespace
Print M.duplicate '' "M.duolicate"
Print N.duplicate '' "M.duplicate"
'Print M.P.duplicate '' error
Code: Select all
Dim Shared As Zstring * 32 duplicate = "..duplicate"
Namespace M
' Dim As Zstring * 32 duplicate = "M.duplicate"
Namespace P
End namespace
End Namespace
Namespace N
Using M
End Namespace
'Print M.duplicate '' error
'Print N.duplicate '' error
'Print M.P.duplicate '' error
Examples for b):
Code: Select all
Dim Shared As Zstring * 32 duplicate = "..duplicate"
Namespace M
Dim As Zstring *32 duplicate = "M.duplicate"
End Namespace
Namespace N
Dim As Zstring * 32 duplicate = "N.duplicate"
Type Parent Extends Object
Dim As Zstring * 32 duplicate = "N.Parent.duplicate"
End Type
Type Child Extends Parent
Dim As Zstring * 32 duplicate = "N.Child.duplicate"
End Type
Type GrandChild Extends Child
Dim As Zstring * 32 duplicate = "N.GrandChild.duplicate"
Declare Sub test()
End Type
End Namespace
Sub N.GrandChild.test()
Using M
Print Base.duplicate
End Sub
Dim As N.GrandChild gc
gc.test() '' "N.Child.duplicate"
Code: Select all
Dim Shared As Zstring * 32 duplicate = "..duplicate"
Namespace M
Dim As Zstring *32 duplicate = "M.duplicate"
End Namespace
Namespace N
Dim As Zstring * 32 duplicate = "N.duplicate"
Type Parent Extends Object
Dim As Zstring * 32 duplicate = "N.Parent.duplicate"
End Type
Type Child Extends Parent
' Dim As Zstring * 32 duplicate = "N.Child.duplicate"
End Type
Type GrandChild Extends Child
Dim As Zstring * 32 duplicate = "N.GrandChild.duplicate"
Declare Sub test()
End Type
End Namespace
Sub N.GrandChild.test()
Using M
Print Base.duplicate
End Sub
Dim As N.GrandChild gc
gc.test() '' "N.Parent.duplicate"
Code: Select all
Dim Shared As Zstring * 32 duplicate = "..duplicate"
Namespace M
Dim As Zstring *32 duplicate = "M.duplicate"
End Namespace
Namespace N
Dim As Zstring * 32 duplicate = "N.duplicate"
Type Parent Extends Object
' Dim As Zstring * 32 duplicate = "N.Parent.duplicate"
End Type
Type Child Extends Parent
' Dim As Zstring * 32 duplicate = "N.Child.duplicate"
End Type
Type GrandChild Extends Child
Dim As Zstring * 32 duplicate = "N.GrandChild.duplicate"
Declare Sub test()
End Type
End Namespace
Sub N.GrandChild.test()
Using M
Print Base.duplicate
End Sub
Dim As N.GrandChild gc
gc.test() '' error