On 02/28/2013 05:55 AM, Walter Bright wrote:
On 2/27/2013 8:01 PM, deadalnix wrote:
Plus, this is really hard to ensure that everything is initialized
properly
without going eager with setting to init.
Yeah, the forward reference order of evaluation thingie.
It's really easy. DMD can be convinced to do a sufficient conservative
analysis even now, but the behaviour is undocumented and seems
unintentional.
void main() {
void foo()() { bar(); }
void bar()() { i = 3; }
int i;
foo();
}
It's a fine idea to disallow the use of both a shadowed and the
shadowing symbol in the same function anyway, so we wouldn't lose a lot
by allowing forward references from local functions.
Then the template behaviour could be fixed:
int i = 0;
void main(){
void foo(int x){ i = x; }
foo(1);
int i = 0;
foo(2);
assert(.i==2&&i==0);
}
int i = 0;
void main(){
void foo(int x){ i = x; }
// foo(1);
int i = 0;
foo(2);
assert(.i==0&&.i==2);
}
(Currently, presence of one call can magically influence the behaviour
of other calls.)