Hi Nick,

>
> Is there any interest in having enums as class constants?
>
> I'm often finding cases where I would like to have an enum inside of a
> class, but don't want a free-floating enum that's basically like
> another class.
>
>
...<snip>...


>
> class SSHClient {
>
>    public const enum CommandResult
>    {
>        case Success;
>        case Failure;
>        case Unknown;
>        case Timeout;
>    }
>
>    // ...
> }
>
>
> // Usage:
>
> SSHClient::CommandResult::Success
>


I feel this topic could be maybe more broad and be called "nested classes"
that are already supported in multiple languages: Java, Swift, Python, C#,
C++, JavaScript, etc.

The syntax you showed is usually identical with what other languages use,
except that probably the const is unnecessary.
The nested class can have visibility as sometimes having it private makes
sense.
Accessing it through `::` is probably fine, but a deeper look at the
grammar might be necessary.
The nested class would have access to parent class private properties and
methods.

I also mentioned this topic on the subject of defining a type in an
autoloader compatible way.
And indeed, a type could also be defined nested in a class if we want to
support that as well.

Now, this feature is not simple, and I think it needs proper sponsorship
from someone experienced with internals.

Regards,
Alex

Reply via email to