GNOME Bugzilla – Bug 514801
Can't have a void function call in the third clause of a for-loop declaration
Last modified: 2008-05-23 08:57:19 UTC
Please describe the problem: You can't have a void function call in the third ("incrementor") clause of a for-loop declaration. Steps to reproduce: using GLib; public class Foo { private static int i; public static void incr(){ ++i; } public static int main() { for(i=0; i<10; incr()) { stdout.printf("%d\n", i); } return 0; }// main }// Foo Actual results: error: invocation of void method not allowed as expression Expected results: Successful compilation Does this happen every time? Yes. Other information:
Confirming.
Created attachment 110713 [details] [review] allowed initializer & iterator of for loop to be void method invocation Updated test case: using GLib; public class Foo { private static int i; public static void incr(){ ++i; } public static void init(){ i=0; } public static int main() { for(init(); i<10; incr()) { stdout.printf("%d\n", i); } return 0; }// main }// Foo
Thanks for the patch.
2008-05-23 Jürg Billeter <j@bitron.ch> * vala/valasemanticanalyzer.vala: Allow invocation of void methods as initializer and iterator in for statements, patch by Jared Moore, fixes bug 514801 * tests/Makefile.am: * tests/statements-iteration.exp: * tests/statements-iteration.vala: Test void methods in for statements Fixed in r1405.