Subtyping of an enum
XavierAP
n3minis-git at yahoo.es
Mon Apr 15 12:25:38 UTC 2019
On Monday, 15 April 2019 at 10:34:42 UTC, Anton Fediushin wrote:
> On Monday, 15 April 2019 at 10:06:30 UTC, XavierAP wrote:
>>
>> You have defined your sub-typing the opposite way that you
>> wanted it to work: every `Enum` is an `internal`, but the
>> other way around an `internal` may not work as an `Enum`. Your
>> `fun` would in principle work if it were defined with an
>> `internal` but passed an `Enum`... Of course you have defined
>> `internal` as nested private so no... But then how did you
>> want anything to work if no one outside Enum knows the
>> super-type?
>
> Isn't this how subtyping works for integers and other types?
> For example, you have subtyped an integer and added some new
> methods to it?
Yes (leaving aside whether stuff is private or nested) but you
are using the types' relationship the other way around. You have:
static assert(is(Enum : internal));
But you are defining and calling fun() as if it were the other
way around (internal : Enum)
More information about the Digitalmars-d-learn
mailing list