[vala] Fix error propagation in constructor chain up



commit 7d86c805dc8cc246a08f3c374a89eb1d5ce05085
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jun 28 22:21:59 2010 +0200

    Fix error propagation in constructor chain up
    
    Fixes bug 623049.

 codegen/valaccodemethodcallmodule.vala |    4 +---
 codegen/valagerrormodule.vala          |    3 +--
 tests/Makefile.am                      |    1 +
 tests/errors/bug623049.vala            |   25 +++++++++++++++++++++++++
 vala/valamethodcall.vala               |   13 +++++++++++++
 5 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 5defe46..e6218fa 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -636,9 +636,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			}
 		}
 
-		if (m is CreationMethod && m.get_error_types ().size > 0) {
-			out_arg_map.set (get_param_pos (-1), new CCodeIdentifier ("error"));
-		} else if (expr.tree_can_fail) {
+		if (expr.tree_can_fail) {
 			// method can fail
 			current_method_inner_error = true;
 			// add &inner_error before the ellipsis arguments
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 36c63ec..b86cfa6 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -117,8 +117,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 
 		if (current_method is CreationMethod) {
 			var cl = current_method.parent_symbol as Class;
-			var unref_call = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
-			unref_call.add_argument (new CCodeIdentifier ("self"));
+			var unref_call = get_unref_expression (new CCodeIdentifier ("self"), new ObjectType (cl), null);
 			cerror_block.add_statement (new CCodeExpressionStatement (unref_call));
 			cerror_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
 		} else if (current_method != null && current_method.coroutine) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 236e316..dcaf3f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -71,6 +71,7 @@ TESTS = \
 	errors/bug567181.vala \
 	errors/bug579101.vala \
 	errors/bug596228.vala \
+	errors/bug623049.vala \
 	asynchronous/bug595735.vala \
 	asynchronous/bug595755.vala \
 	asynchronous/bug596177.vala \
diff --git a/tests/errors/bug623049.vala b/tests/errors/bug623049.vala
new file mode 100644
index 0000000..913f6cd
--- /dev/null
+++ b/tests/errors/bug623049.vala
@@ -0,0 +1,25 @@
+public errordomain Foo {
+	BAR
+}
+
+class ClsA : Object {
+	public ClsA () throws Error {
+		throw new Foo.BAR ("Test");
+	}
+}
+
+class ClsB: ClsA {
+	public ClsB () throws Error {
+		base ();
+
+		assert_not_reached ();
+	}
+}
+
+void main () {
+	try {
+		new ClsB ();
+	} catch (Error e) {
+		debug ("Propagated error");
+	}
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index a148699..79b7ecf 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -615,6 +615,19 @@ public class Vala.MethodCall : Expression {
 					value_type = formal_value_type.get_actual_type (target_object_type, call as MemberAccess, this);
 				}
 			}
+		} else if (mtype is ObjectType) {
+			// constructor
+			var cl = (Class) ((ObjectType) mtype).type_symbol;
+			var m = cl.default_construction_method;
+			foreach (DataType error_type in m.get_error_types ()) {
+				may_throw = true;
+
+				// ensure we can trace back which expression may throw errors of this type
+				var call_error_type = error_type.copy ();
+				call_error_type.source_reference = source_reference;
+
+				add_error_type (call_error_type);
+			}
 		} else if (mtype is DelegateType) {
 			var d = ((DelegateType) mtype).delegate_symbol;
 			foreach (DataType error_type in d.get_error_types ()) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]