[fpc-pascal] Name collisions in scoped enums

Sven Barth pascaldragon at googlemail.com
Mon May 4 20:02:45 CEST 2020


Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mo., 4. Mai 2020, 18:58:

>
>
> > 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.
>

Keywords have a higher precedence and are handled in the scanner. This will
not be changed.


> 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.
>

No, because there could be a method A that returns a TName.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200504/1c78e46f/attachment.htm>


More information about the fpc-pascal mailing list