[fpc-pascal] Name collisions in scoped enums

Ryan Joseph genericptr at gmail.com
Mon May 4 17:04:04 CEST 2020



> On May 4, 2020, at 2:12 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
> 
> Methods can't be keywords either, unless prefixed with &.
> 
> It's not safe to change this, that's why a keyword is a keyword: it supersedes all identifiers, it is part of the language.

Yes but methods can be used without their class prefix so they aren't comparable as identifiers the same way scoped enums are, because scoped enums require the prefix to be valid at all. Always, that's fine, I just wanted to make sure this wasn't an omission by accident.

Speaking of that I just remembered something else. In Swift I liked that they allowed scoped enums to be used without their prefix in the instance that they are assigned to a compatible type, or in the correct context.

For example if you have an enum 
 
TNames = (A, B, C);

and a function 
	
SayNames(names: TNames);

you can call it as SayNames([A, B]); and this is valid because of the context.

Is that possible to implement in scoped enums? It's a nice time saver to not have to deal with the prefix when the context is correct but you still get the namespace protection in the rest of the program.

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list