[Issue 10253] Switch and Final Switch do not work with subtyping

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 3 10:05:55 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10253



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-03 10:05:54 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> 
> > I *thought* that switching on a struct was already
> > possible. But it isn't, so there's no ambiguity here.
> 
> The enhancement request for structs in switches is Issue 596 (Issue 596 also
> asks for a standard method named unapply() that's called by the switch).

I see. In that case the following would be an ambiguity:

-----
enum E { a, b }

struct S
{
    int x;
    E e;
    alias e this;
}

auto s = S(0, E.a);
switch (s)  // switch on 's' value or 's.e' value?
{
}
-----

In that case I propose the subtype switch would only work if the struct has
only one member which is the alias this variable:

-----
struct S
{
    E e;
    alias e this;
}

auto s = S(E.a);
switch (s)  // ok: equivalent to switch on 's.e'
{
}
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list