D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1908 - Various closure problems
Summary: Various closure problems
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-11 19:23 UTC by David Friedman
Modified: 2015-06-09 01:14 UTC (History)
1 user (show)

See Also:


Attachments
Test case closure5w (387 bytes, text/plain)
2008-03-11 19:25 UTC, David Friedman
Details
Test case closure8w (368 bytes, text/plain)
2008-03-11 19:26 UTC, David Friedman
Details
Test case closure11w (394 bytes, text/plain)
2008-03-11 19:27 UTC, David Friedman
Details
Test case closure13w (591 bytes, text/plain)
2008-03-11 19:28 UTC, David Friedman
Details
Test case closure14 (210 bytes, text/plain)
2008-03-11 19:41 UTC, David Friedman
Details

Note You need to log in before you can comment on or make changes to this issue.
Description David Friedman 2008-03-11 19:23:36 UTC
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;
Comment 1 David Friedman 2008-03-11 19:25:14 UTC
Created attachment 234 [details]
Test case closure5w
Comment 2 David Friedman 2008-03-11 19:26:47 UTC
Created attachment 235 [details]
Test case closure8w
Comment 3 David Friedman 2008-03-11 19:27:27 UTC
Created attachment 236 [details]
Test case closure11w
Comment 4 David Friedman 2008-03-11 19:28:07 UTC
Created attachment 237 [details]
Test case closure13w
Comment 5 David Friedman 2008-03-11 19:41:22 UTC
Created attachment 238 [details]
Test case closure14

Similar to closure13w, but causes an ICE.  Also affects DMD 1.x.
Comment 6 Walter Bright 2008-04-24 04:44:46 UTC
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.
Comment 7 Don 2010-10-19 23:55:58 UTC
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.