A switch/case too far...

Koroskin Denis 2korden at gmail.com
Thu May 22 08:21:41 PDT 2008


On Thu, 22 May 2008 17:30:14 +0400, Janice Caron <caron800 at googlemail.com>  
wrote:

> Well, convenience and readability, of course.
>
>     [skip]
>    (in my opinion, at least). That said, I don't really care much about
> this proposal one way or the other. It's only sugar, after all.


terranium most probably found your fault with the following:

> check that the object can be implicitly cast to that type

Since implicit cast always succeeds, there is no need for such a switch,  
that's
why it should work with *explicit* cast only, it's an error otherwise:

class A {
}

class B : A {
}

class C {
}

B a = new B();
switch (b is) {
     case A: // always succeeds, and therefore makes no sense
         break;
     case C:
         doSomething();	// error, unreachable code
         break;
}



More information about the Digitalmars-d mailing list