GNOME Bugzilla – Bug 537706
Recursive lambdas do not work properly
Last modified: 2008-12-16 00:25:24 UTC
For example: using GLib; public class Test : Object { delegate int Accumulates(int x, int acc); public void run() { Accumulates fac; fac = (x, acc) => { if (x <= 1) return acc; else return fac(x - 1, x * acc); }; stdout.printf("Result is: %d\n", fac(5, 1)); } public static void main(string[] args) { new Test().run(); } } Vala compiles this fine, but the generated code has errors. Although Vala probably won't support full closures, recursive lambdas probably shouldn't be too hard to do (in __lambda0 in the generated code, just replace fac_target -> self and fac -> ___lambda0_test_accumulates). I'll see if I can make a patch for this...
Also, note that if "Accumulates fac;" in the example above is made a member of the Test class as opposed to a local variable in run(), the example compiles and runs as expected.
Confirming, it's currently not possible to access any method variable from the body of the lambda method. However, we actually want full closure support, at least to the extent possible.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 554781 ***