digitalmars.D.learn - Default Delegate Parameter
- Jesse Phillips (11/11) Jan 26 2010 For the following code I get the bellow error. I'm wondering if I should...
- BCS (13/30) Jan 26 2010 I don't know if this is a bug or what but I think this happens because t...
- Jesse Phillips (3/31) Jan 26 2010 At least that explains why, should have mentioned I had the work around.
For the following code I get the bellow error. I'm wondering if I should be reporting a bug, or if creating default delegates is correctly prevented? .\defltdg.d(10): Error: delegate defltdg.__dgliteral3 is a nested function and cannot be accessed from main import std.stdio; void main() { take(() {writeln("Hello world");}); take(() {}); take(); } void take(void delegate() dg = () {}) { dg(); }
Jan 26 2010
Hello Jesse,For the following code I get the bellow error. I'm wondering if I should be reporting a bug, or if creating default delegates is correctly prevented? .\defltdg.d(10): Error: delegate defltdg.__dgliteral3 is a nested function and cannot be accessed from main import std.stdio; void main() { take(() {writeln("Hello world");}); take(() {}); take(); } void take(void delegate() dg = () {}) { dg(); }I don't know if this is a bug or what but I think this happens because the default is defined (compile time) in the scope of take but generated (run time) in the scope of main. I'd be fine with a special case for this that either 1) allows a delegate that doesn't access any outer scope to be generated like that or 2) special case the code gen to correctly generate the delegate for the function (the new frame pointer can be computed at that point) work around: void take() { take(() {});} void take(void delegate() dg) { dg(); } -- <IXOYE><
Jan 26 2010
BCS wrote:Hello Jesse,At least that explains why, should have mentioned I had the work around. Thanks.For the following code I get the bellow error. I'm wondering if I should be reporting a bug, or if creating default delegates is correctly prevented? .\defltdg.d(10): Error: delegate defltdg.__dgliteral3 is a nested function and cannot be accessed from main import std.stdio; void main() { take(() {writeln("Hello world");}); take(() {}); take(); } void take(void delegate() dg = () {}) { dg(); }I don't know if this is a bug or what but I think this happens because the default is defined (compile time) in the scope of take but generated (run time) in the scope of main. I'd be fine with a special case for this that either 1) allows a delegate that doesn't access any outer scope to be generated like that or 2) special case the code gen to correctly generate the delegate for the function (the new frame pointer can be computed at that point) work around: void take() { take(() {});} void take(void delegate() dg) { dg(); }
Jan 26 2010