[Issue 3190] enum doesn't work as the increment in a for loop

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 10 05:35:03 PDT 2009


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2009-09-10 05:34:59 PDT ---
There are two problems here.
PROBLEM 1: This problem only shows up in for() loops because the increment
condition isn't doing constant folding. This is a more general problem, which
also affects D1.

statement.c line 1160 (DMD 2.032).

    if (increment)
    {    increment = increment->semantic(sc);
    increment = resolveProperties(sc, increment);
+    increment = increment->optimize(0);
    }

This change is enough to make the bug go away, but there's another oddity:

PROBLEM 2: It only happens for enum real ONE = 1.0; but not for enum : real {
ONE = 1.0 }.
This is because expression.c DsymbolExp::semantic(Scope *sc) checks for enum
members, but not for the new D2 manifest constants. I suspect that it probably
should convert them, too, as in this second patch:

expression.c, line 2168.

    if (v)
    {
    //printf("Identifier '%s' is a variable, type '%s'\n", toChars(),
v->type->toChars());
    if (!type)
    {   type = v->type;
        if (!v->type)
        {    error("forward reference of %s %s", v->kind(), v->toChars());
        type = Type::terror;
        }
    }
+    if ((v->storage_class & STCmanifest) && v->init) {
+        e = v->init->toExpression();
+        e->semantic(sc);
+        return e;
+    }
    e = new VarExp(loc, v);
    e->type = type;
    e = e->semantic(sc);
    return e->deref();
    }

-- 
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