The problem here is use of enclosed locals in nested closures in a field initializer. Although I support closures in field initializers, I don't support the more complicated aspects of what I call "cvars" (enclosed local variables). We could potentially support that, although it ripples thru the compiler pipeline as a fairly complicated boundary condition because the actual enclosing method is the object's constructor for field initializers.
So for now I am going to say we don't support that feature. What I did was detect this case and report a sensible error message: "Nested closures not supported in field initializer" instead of throwing an CastErr.
tactics Sun 19 Apr 2009
I think I found a bug in the compiler. Not sure exactly what's up with it.
This produces the error
brian Mon 20 Apr 2009
Promoted to ticket #542 and assigned to brian
brian Wed 22 Apr 2009
Ticket resolved in 1.0.42
The problem here is use of enclosed locals in nested closures in a field initializer. Although I support closures in field initializers, I don't support the more complicated aspects of what I call "cvars" (enclosed local variables). We could potentially support that, although it ripples thru the compiler pipeline as a fairly complicated boundary condition because the actual enclosing method is the object's constructor for field initializers.
So for now I am going to say we don't support that feature. What I did was detect this case and report a sensible error message: "Nested closures not supported in field initializer" instead of throwing an CastErr.
Work arounds include: