From e01f76b4ac13a0990883e6ce393651e6a09d8a62 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Fri, 23 May 2008 08:44:13 +0000 Subject: [PATCH] Allow invocation of void methods as initializer and iterator in for 2008-05-23 Juerg Billeter * 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 svn path=/trunk/; revision=1405 --- ChangeLog | 13 +++++++++++++ tests/Makefile.am | 2 ++ tests/statements-iteration.exp | 0 tests/statements-iteration.vala | 14 ++++++++++++++ vala/valasemanticanalyzer.vala | 5 ++++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/statements-iteration.exp create mode 100644 tests/statements-iteration.vala diff --git a/ChangeLog b/ChangeLog index 0136fd0..0802206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-05-23 Jürg Billeter + + * 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 + 2008-05-22 Jürg Billeter * vapi/Makefile.am: diff --git a/tests/Makefile.am b/tests/Makefile.am index bee987b..caa9625 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,7 @@ TESTS = \ expressions-assignments.vala \ expressions-lambda.vala \ statements-selection.vala \ + statements-iteration.vala \ statements-jump.vala \ namespaces.vala \ classes.vala \ @@ -59,6 +60,7 @@ EXTRA_DIST = \ expressions-assignments.exp \ expressions-lambda.exp \ statements-selection.exp \ + statements-iteration.exp \ statements-jump.exp \ namespaces.exp \ classes.exp \ diff --git a/tests/statements-iteration.exp b/tests/statements-iteration.exp new file mode 100644 index 0000000..e69de29 diff --git a/tests/statements-iteration.vala b/tests/statements-iteration.vala new file mode 100644 index 0000000..c435c04 --- /dev/null +++ b/tests/statements-iteration.vala @@ -0,0 +1,14 @@ +void void_method () { +} + +// http://bugzilla.gnome.org/show_bug.cgi?id=514801 +void test_for_void_methods () { + for (void_method (); ; void_method ()) { + break; + } +} + +void main () { + test_for_void_methods (); +} + diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index a01d269..d954c83 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -1827,7 +1827,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor { if (ret_type is VoidType) { // void return type - if (!(expr.parent_node is ExpressionStatement)) { + if (!(expr.parent_node is ExpressionStatement) + && !(expr.parent_node is ForStatement)) { + // A void method invocation can be in the initializer or + // iterator of a for statement expr.error = true; Report.error (expr.source_reference, "invocation of void method not allowed as expression"); return; -- 2.7.4