Bug 4564 – ICE on undefined variable in foreach over 0 .. undef

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-08-01T15:25:00Z
Last change time
2010-08-27T21:36:47Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
braddr

Comments

Comment #0 by braddr — 2010-08-01T15:25:34Z
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 }
Comment #1 by clugdbug — 2010-08-10T00:45:06Z
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(); } }
Comment #2 by braddr — 2010-08-11T17:29:32Z
*** Issue 4626 has been marked as a duplicate of this issue. ***
Comment #3 by bugzilla — 2010-08-27T21:36:47Z