D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.

Issue 1908

Summary: Various closure problems
Product: D Reporter: David Friedman <dvdfrdmn>
Component: dmdAssignee: 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

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.

AltStyle によって変換されたページ (->オリジナル) /