Thread overview | |||||
---|---|---|---|---|---|
|
January 26, 2010 Default Delegate Parameter | ||||
---|---|---|---|---|
| ||||
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(); } |
January 26, 2010 Re: Default Delegate Parameter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | 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><
|
January 27, 2010 Re: Default Delegate Parameter | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> 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(); }
At least that explains why, should have mentioned I had the work around.
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation