From: Juerg Billeter Date: Tue, 7 Aug 2007 22:08:19 +0000 (+0000) Subject: support exceptions in foreach collection expressions, fix test X-Git-Tag: VALA_0_1_3~112 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26f630d6c5d0ff6db59c2398ef9259376d05f95b;p=platform%2Fupstream%2Fvala.git support exceptions in foreach collection expressions, fix test 2007-08-08 Juerg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index 0d9f132..3e5972a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-08-08 Jürg Billeter + + * 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 * tests/test-033.vala, tests/testrunner.sh: test exception handling when diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 8832bae..7ac583b 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -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) { diff --git a/tests/test-033.out b/tests/test-033.out index e884946..2ad46aa 100644 --- a/tests/test-033.out +++ b/tests/test-033.out @@ -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 diff --git a/tests/test-033.vala b/tests/test-033.vala index af2398c..38a24ee 100644 --- a/tests/test-033.vala +++ b/tests/test-033.vala @@ -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; } diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 4fabb1b..425032a 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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) {