Thread overview
[Issue 4564] New: ICE on undefined variable in foreach over 0 .. undef
Aug 01, 2010
Brad Roberts
Aug 10, 2010
Don
Aug 12, 2010
Brad Roberts
Aug 28, 2010
Walter Bright
August 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4564

           Summary: ICE on undefined variable in foreach over 0 .. undef
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: braddr@puremagic.com


--- Comment #0 from Brad Roberts <braddr@puremagic.com> 2010-08-01 15:25:34 PDT ---
module test;
int main()
{
    foreach(i; 0 .. undef) {}
    return 0;
}

foreach.d(4): Error: undefined identifier undef
dmd: statement.c:2242: virtual int ForeachRangeStatement::blockExit():
Assertion `0' failed.

The code:
int ForeachRangeStatement::blockExit()
{
    assert(0);
    ... more code, but not reachable
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4564


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

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


--- Comment #1 from Don <clugdbug@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: -------
August 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4564


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kulhanek.5@wright.edu


--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2010-08-11 17:29:32 PDT ---
*** Issue 4626 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4564


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2010-08-27 21:36:47 PDT ---
http://www.dsource.org/projects/dmd/changeset/636

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