The following code:
TYPE MenuState as integer
TYPE TTT
DECLARE SUB method()
menustate as MenuState
zonemenustate as MenuState
END TYPE
produces the error:
bug.bas(7) error 14: Expected identifier, found 'MenuState' in 'zonemenustate as MenuState'
That's fine. But if you comment out the DECLARE SUB method() line then the TTT type is no longer treated as a class and you get no error, apparently because different rules apply. Strange and unexpected.
Using a git build that's half a year old (just before FB 1.06)
The parser is not as smart as the person who codes.
Some rules, sometimes not completely logical, have been implemented to solve name duplication problems.
By the way, there are still bugs about it:
https://sourceforge.net/p/fbc/bugs/645/
For this particular syntax, you can help parser by meaning when the used name is not local but global:
The rule:
Last edit: fxm (freebasic.net) 2021-12-25
Thanks, that trick hadn't occurred to me.
I had always assumed that FB has separate namespaces for types and for other identifiers, because you can usually, but not always, reuse the name of a type as a variable name. Is that wrong? Inability of the parser to determine whether an identifier names a type or not in certain contexts could explain the inconsistency I see.
This is a duplicate of [#583]: global type names are shadowed by UDT fields. But in this report I showed that it only happens when the UDT has methods.
Related
Bugs: #583