vala r2086 - in trunk: . vala



Author: juergbi
Date: Sat Nov 29 18:59:26 2008
New Revision: 2086
URL: http://svn.gnome.org/viewvc/vala?rev=2086&view=rev

Log:
2008-11-29  JÃrg Billeter  <j bitron ch>

	* vala/valamethodcall.vala:

	Fix error handling in inner expressions, fixes bug 475922


Modified:
   trunk/ChangeLog
   trunk/vala/valamethodcall.vala

Modified: trunk/vala/valamethodcall.vala
==============================================================================
--- trunk/vala/valamethodcall.vala	(original)
+++ trunk/vala/valamethodcall.vala	Sat Nov 29 18:59:26 2008
@@ -391,9 +391,13 @@
 		formal_value_type = ret_type;
 		value_type = formal_value_type.get_actual_type (target_object_type, this);
 
+		bool may_throw = false;
+
 		if (mtype is MethodType) {
 			var m = ((MethodType) mtype).method_symbol;
 			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;
@@ -404,6 +408,30 @@
 
 		analyzer.check_arguments (this, mtype, params, get_argument_list ());
 
+		if (may_throw) {
+			if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
+				// simple statements, no side effects after method call
+			} else {
+				// store parent_node as we need to replace the expression in the old parent node later on
+				var old_parent_node = parent_node;
+
+				var local = new LocalVariable (value_type, get_temp_name (), null, source_reference);
+				var decl = new DeclarationStatement (local, source_reference);
+
+				insert_statement ((Block) analyzer.current_symbol, decl);
+
+				var temp_access = new MemberAccess.simple (local.name, source_reference);
+				temp_access.target_type = target_type;
+
+				// don't set initializer earlier as this changes parent_node and parent_statement
+				local.initializer = this;
+				decl.check (analyzer);
+				temp_access.check (analyzer);
+
+				old_parent_node.replace_expression (this, temp_access);
+			}
+		}
+
 		return !error;
 	}
 



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