check that void return values are not used, fixes bug 434503
authorJürg Billeter <j@bitron.ch>
Mon, 30 Apr 2007 08:50:08 +0000 (08:50 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 30 Apr 2007 08:50:08 +0000 (08:50 +0000)
2007-04-30  Jürg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala: check that void return values are not
  used, fixes bug 434503

svn path=/trunk/; revision=291

vala/ChangeLog
vala/vala/valasemanticanalyzer.vala

index 76d2025..6c3d2d1 100644 (file)
@@ -1,5 +1,10 @@
 2007-04-30  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valasemanticanalyzer.vala: check that void return values are not
+         used, fixes bug 434503
+
+2007-04-30  Jürg Billeter  <j@bitron.ch>
+
        * vala/valasemanticanalyzer.vala: fix type check in relational
          operations, fixes bug 434507
 
index c9dcc7a..547dc87 100644 (file)
@@ -123,23 +123,24 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
        
        private ref List<DataType> get_all_prerequisites (Interface! iface) {
-               weak List<DataType> ret = null;
-               
+               List<DataType> ret = null;
+
                foreach (TypeReference prereq in iface.get_prerequisites ()) {
                        DataType type = prereq.data_type;
                        /* skip on previous errors */
                        if (type == null) {
                                continue;
                        }
-                       
+
                        ret.prepend (type);
                        if (type is Interface) {
-                               ret.concat (get_all_prerequisites ((Interface)type));
+                               ret.concat (get_all_prerequisites ((Interface) type));
                                
                        }
                }
-               
-               return ret.reverse ();
+
+               ret.reverse ();
+               return #ret;
        }
        
        private bool class_is_a (Class! cl, DataType! t) {
@@ -1274,6 +1275,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        ret_type = m.get_return_type ();
                        params = m.get_parameters ();
 
+                       if (ret_type.data_type == null && ret_type.type_parameter == null) {
+                               // void return type
+                               if (!(expr.parent_node is ExpressionStatement)) {
+                                       expr.error = true;
+                                       Report.error (expr.source_reference, "invocation of void method not allowed as expression");
+                                       return;
+                               }
+                       }
+
                        // resolve generic return values
                        if (ret_type.type_parameter != null) {
                                if (!(expr.call is MemberAccess)) {