I have a feature request: "Named enum scope inference"

Jonathan M Davis jmdavisProg at gmx.com
Fri Sep 28 20:07:45 PDT 2012


On Saturday, September 29, 2012 03:55:48 Tommi wrote:
> enum MyFruit { apple, orange, banana }
> 
> MyFruit fruit;
> 
> switch (fruit)
> {
>      case apple:  break; // Case expressions know what type to
>      case orange: break; // expect based on the switch expression
>      case banana: break;
> }

This could be achieved by simply making it so that when a variable of an enum 
type is used in a switch statement, the cases permit you to omit the enum's 
type when referring to the enum values. None of the name inferrence stuff that 
you're suggesting would be required for that. Though at the moment, I believe 
that you could simply use with to solve the problem:

with(MyFruit)
{
    switch(fruit)
    {
        case apple: break;
        case orange: break;
        case banana: break;
    }
}

All that would be required to do it without the with would be to make it so 
that the compiler implicitly added the with when an enum type is used in the 
switch.

- Jonathan M Davis


More information about the Digitalmars-d mailing list