Commit 26f630d6 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

support exceptions in foreach collection expressions, fix test

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
parent 40ed027f
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
......
......@@ -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) {
......
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
......@@ -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;
}
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment