Summary: | Various closure problems | ||
---|---|---|---|
Product: | D | Reporter: | David Friedman <dvdfrdmn> |
Component: | dmd | Assignee: | Walter Bright <bugzilla> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | clugdbug |
Priority: | P2 | Keywords: | wrong-code |
Version: | D2 | ||
Hardware: | All | ||
OS: | All | ||
Attachments: |
Test case closure5w
Test case closure8w Test case closure11w Test case closure13w Test case closure14 |
Attached closure-related test cases fail. closure5w.d: Segfaults. Only f() creates a closure and 'dg = & i' does not get a valid reference to it. closure8w.d: Fails with ArrayBoundsError. closure11w.d: Assert fails. The tests in Function::needsClosure only check f->isVirtual(), but a virtual function can call a non-virtual function which does non-local access. I fixed this in GDC by testing f->isThis() instead. closure13w.d: Assert fails. DotVarExp::semantic does not call checkNestedReference for the 'this' of an outer function. I fixed this in GDC by adding a semantic() call: // Skip over nested functions, and get the enclosing // class type. Dsymbol *s = tcd->toParent(); while (s && s->isFuncDeclaration()) { FuncDeclaration *f = s->isFuncDeclaration(); if (f->vthis) { e1 = new VarExp(loc, f->vthis); } s = s->toParent(); } if (s && s->isClassDeclaration()) e1->type = s->isClassDeclaration()->type; + e1 = e1->semantic(sc); // Added to get corrected nested refs goto L1;
Created attachment 234 [details]
Test case closure5w
Created attachment 235 [details]
Test case closure8w
Created attachment 236 [details]
Test case closure11w
Created attachment 237 [details]
Test case closure13w
Created attachment 238 [details]
Test case closure14
Similar to closure13w, but causes an ICE. Also affects DMD 1.x.
Patches for 11w and 13w were folded in to DMD 2.013. 13w was folded in to DMD 1.029, fixing 14. 5w and 8w are left.
Test case 8w is a duplicate of bug 3326, and isn't actually a closure bug. Test case 5w is a duplicate of bug 1841. I'm therefore closing this bug, as the other cases have been fixed.