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



--- Comment #9 from Don <clugd...@yahoo.com.au> 2011-07-08 06:51:56 PDT ---
(In reply to comment #8)
> Well, it works with variables which are of type int. 

Wow. I just checked, and you're right. That's disturbing.

Here's the code in statement.c:

        /* This is where variables are allowed as case expressions.
         */
        if (exp->op == TOKvar)
        {   VarExp *ve = (VarExp *)exp;
            VarDeclaration *v = ve->var->isVarDeclaration();
            Type *t = exp->type->toBasetype();
            if (v && (t->isintegral() || t->ty == Tclass))
            {   /* Flag that we need to do special code generation
                 * for this, i.e. generate a sequence of if-then-else
                 */
                sw->hasVars = 1;
                if (sw->isFinal)
                    error("case variables not allowed in final switch
statements");
                goto L1;
            }
        }

Note that it only allows integers AND CLASSES!
I think this is a *major* misfeature. But you're right, and I was wrong -- this
behaviour is clearly intentional for the integer case, and it makes absolutely
no sense to allow it for integers but not for strings.

So TDPL, the spec, and DMD are all different from each other.

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

Reply via email to