Bug 10741 – A delegate in a variable initializer cannot see the variable

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-01T12:05:25Z
Last change time
2024-12-13T18:09:56Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#18639 →

Comments

Comment #0 by andrej.mitrovich — 2013-08-01T12:05:25Z
This is an interesting limitation: ----- struct Foo { this(void delegate()) { } void test() { } } void main() { Foo foo1; foo1 = Foo({ foo1.test(); }); // ok Foo foo2 = Foo({ foo2.test(); }); // L14: error } ----- $ dmd test.d > test.d(14): Error: undefined identifier foo2, did you mean variable foo1? It seems the delegate cannot see the 'foo2' variable yet. I'm not sure if there would be any problems making this work?
Comment #1 by maxim — 2013-08-01T12:19:09Z
Yes, because a declaration with initializer is not finished in the point of initializer. This is a basic feature in D. void main() { @((int i)=>a) int a; //error auto b = { return b; } ; //error } However nothing is wrong with making this limitation gone.
Comment #2 by robert.schadek — 2024-12-13T18:09:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18639 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB