Lars T. Kyllingstad wrote: > If I've understood things correctly, by marking a delegate parameter with > 'scope' you tell the compiler not to create a true closure for the > delegate. Effectively you're saying "I promise not to escape this > delegate, so you don't need to copy its context to the heap". > > In brief, my question is: Why doesn't the compiler enforce this > promise? In particular, why is 'scope' not a type constructor? > > (Note that this is mostly a question out of curiosity, and not really a > proposal for a new feature. I imagine it has been discussed in the past > and rejected for some reason.) > > Considering that the compiler enforces proper use of pure, nothrow, > const, and all those other things, it doesn't seem much harder to do the > same with scope. > > As an example, I really can't see a reason why obviously wrong code like > this should be allowed: > > void delegate() globalDg; > > void foo(scope void delegate() dg) > { > globalDg = dg; > }
Most likely it is not yet implemented? It's hard to find something on this topic, I couldn't find anything in the spec or tdpl. I did found this one post by Andrei about your question: http://permalink.gmane.org/gmane.comp.lang.d.concurrency/617 > Here's a slightly less obvious example, which also compiles successfully: > > void foo(void delegate() dg); // Who knows what this does? > > void bar(scope void delegate() dg) > { > foo(dg); > } > > -Lars