After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 514801 - Can't have a void function call in the third clause of a for-loop declaration
Can't have a void function call in the third clause of a for-loop declaration
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Semantic Analyzer
0.1.x
Other All
: Normal minor
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-06 16:51 UTC by Levi Bard
Modified: 2008-05-23 08:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
allowed initializer & iterator of for loop to be void method invocation (640 bytes, patch)
2008-05-11 11:24 UTC, Jared Moore
committed Details | Review

Description Levi Bard 2008-02-06 16:51:37 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:
Comment 1 Jürg Billeter 2008-02-06 17:03:07 UTC
Confirming.
Comment 2 Jared Moore 2008-05-11 11:24:14 UTC
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
Comment 3 Jürg Billeter 2008-05-23 08:45:31 UTC
Thanks for the patch.
Comment 4 Jürg Billeter 2008-05-23 08:57:19 UTC
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.