support exceptions in foreach collection expressions, fix test
authorJuerg Billeter <j@bitron.ch>
Tue, 7 Aug 2007 22:08:19 +0000 (22:08 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 7 Aug 2007 22:08:19 +0000 (22:08 +0000)
2007-08-08  Juerg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala, gobject/valacodegenerator.vala,
  tests/test-033.out, tests/test-033.vala: support exceptions in foreach
  collection expressions, fix test

svn path=/trunk/; revision=442

ChangeLog
gobject/valacodegenerator.vala
tests/test-033.out
tests/test-033.vala
vala/valasemanticanalyzer.vala

index 0d9f132..3e5972a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-08  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valasemanticanalyzer.vala, gobject/valacodegenerator.vala,
+         tests/test-033.out, tests/test-033.vala: support exceptions in foreach
+         collection expressions, fix test
+
 2007-08-07  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
 
        * tests/test-033.vala, tests/testrunner.sh: test exception handling when
index 8832bae..7ac583b 100644 (file)
@@ -1358,6 +1358,13 @@ public class Vala.CodeGenerator : CodeVisitor {
                ccoldecl.add_declarator (new CCodeVariableDeclarator.with_initializer (collection_backup.name, (CCodeExpression) stmt.collection.ccodenode));
                cblock.add_statement (ccoldecl);
                
+               if (stmt.tree_can_fail && stmt.collection.can_fail) {
+                       // exception handling
+                       var cfrag = new CCodeFragment ();
+                       add_simple_check (stmt.collection, cfrag);
+                       cblock.add_statement (cfrag);
+               }
+
                stmt.ccodenode = cblock;
                
                if (stmt.collection.static_type.data_type is Array) {
index e884946..2ad46aa 100644 (file)
@@ -1 +1 @@
-Exception Test: 1 2 3 4 5 6 7 8 9 10 11
+Exception Test: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
index af2398c..38a24ee 100644 (file)
@@ -35,7 +35,7 @@ class Maman.Bar {
                result.add (" FOO");
                result.add (" BAR");
 
-               throw new BarError.LIST (" 14");
+               throw new BarError.LIST (" 12");
 
                return result;
        }
@@ -65,21 +65,21 @@ class Maman.Bar {
 
                try {
                        foreach (string s in list ()) {
-                               stdout.printf (" 11");
+                               stdout.printf (" BAD");
 
                                stdout.printf (" %s", s);
 
-                               stdout.printf (" 12");
+                               stdout.printf (" BAD");
                        }
                } catch (BarError e) {
-                       stdout.printf (" 13");
+                       stdout.printf (" 11");
 
                        stdout.printf ("%s", e.message);
 
-                       stdout.printf (" 15");
+                       stdout.printf (" 13");
                }
 
-               stdout.printf (" 16");
+               stdout.printf (" 14");
        }
 
        static int main (string[] args) {
@@ -88,7 +88,7 @@ class Maman.Bar {
                var bar = new Bar ();
                bar.run ();
 
-               stdout.printf (" 17\n");
+               stdout.printf (" 15\n");
                
                return 0;
        }
index 4fabb1b..425032a 100644 (file)
@@ -901,6 +901,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        Report.error (stmt.source_reference, "Collection not iterable");
                        return;
                }
+
+               stmt.tree_can_fail = stmt.collection.tree_can_fail || stmt.body.tree_can_fail;
        }
 
        public override void visit_end_return_statement (ReturnStatement! stmt) {