[Issue 4564] ICE on undefined variable in foreach over 0 .. undef

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 10 00:45:08 PDT 2010


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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2010-08-10 00:45:06 PDT ---
When an error occurs in ForeachRangeStatement::semantic, it returns this.
That's a problem because foreachrangestatement doesn't support blockExit;
foreachrange MUST be turned into a for statement during the semantic pass.
I found a few variations of this error.

Now that we have a working _error type, it seems perfectly fine to just let it
through: the test suite passes. This also has the advantage that errors in the
foreach body are reported.

PATCH:

Statement *ForeachRangeStatement::semantic, line 2130.


        /* Must infer types from lwr and upr
         */
        Type *tlwr = lwr->type->toBasetype();
        if (tlwr->ty == Tstruct || tlwr->ty == Tclass)
        {
            /* Just picking the first really isn't good enough.
             */
            arg->type = lwr->type->mutableOf();
        }
        else
        {
            AddExp ea(loc, lwr, upr);
            Expression *e = ea.typeCombine(sc);
-            if (e->op == TOKerror)
-                return this;
            arg->type = ea.type->mutableOf();
            lwr = ea.e1;
            upr = ea.e2;
        }

EXTENDED TEST CASE
struct Bug4564{}

void bug4564()
{
    foreach(i; 3.1 ..Bug4564()) {
        foreach(j; 2.1..Bug4564()) {}
    }
    foreach(i; 0..undef){
       thisShouldGenerateAnError(); 
     }
}

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