vala r1920 - in trunk: . vala



Author: juergbi
Date: Sat Oct 25 14:54:29 2008
New Revision: 1920
URL: http://svn.gnome.org/viewvc/vala?rev=1920&view=rev

Log:
2008-10-25  JÃrg Billeter  <j bitron ch>

	* vala/valasemanticanalyzer.vala:

	Fix crash with invalid return values, fixes bug 549996


Modified:
   trunk/ChangeLog
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Sat Oct 25 14:54:29 2008
@@ -1198,33 +1198,41 @@
 			return;
 		}
 
-		if (stmt.return_expression == null && !(current_return_type is VoidType)) {
-			stmt.error = true;
-			Report.error (stmt.source_reference, "Return without value in non-void function");
-			return;
+		if (stmt.return_expression == null) {
+			if (current_return_type is VoidType) {
+				return;
+			} else {
+				stmt.error = true;
+				Report.error (stmt.source_reference, "Return without value in non-void function");
+				return;
+			}
 		}
 
-		if (stmt.return_expression != null && current_return_type is VoidType) {
+		if (current_return_type is VoidType) {
 			Report.error (stmt.source_reference, "Return with value in void function");
 			return;
 		}
 
-		if (stmt.return_expression != null &&
-		     !stmt.return_expression.value_type.compatible (current_return_type)) {
+		if (stmt.return_expression.value_type == null) {
+			stmt.error = true;
+			Report.error (stmt.source_reference, "Invalid expression in return value");
+			return;
+		}
+
+		if (!stmt.return_expression.value_type.compatible (current_return_type)) {
+			stmt.error = true;
 			Report.error (stmt.source_reference, "Return: Cannot convert from `%s' to `%s'".printf (stmt.return_expression.value_type.to_string (), current_return_type.to_string ()));
 			return;
 		}
 
-		if (stmt.return_expression != null &&
-		    stmt.return_expression.value_type.is_disposable () &&
+		if (stmt.return_expression.value_type.is_disposable () &&
 		    !current_return_type.value_owned) {
 			stmt.error = true;
 			Report.error (stmt.source_reference, "Return value transfers ownership but method return type hasn't been declared to transfer ownership");
 			return;
 		}
 
-		if (stmt.return_expression != null &&
-		    stmt.return_expression.symbol_reference is LocalVariable &&
+		if (stmt.return_expression.symbol_reference is LocalVariable &&
 		    stmt.return_expression.value_type.is_disposable () &&
 		    !current_return_type.value_owned) {
 			Report.warning (stmt.source_reference, "Local variable with strong reference used as return value and method return type hasn't been declared to transfer ownership");
@@ -1235,9 +1243,7 @@
 			Report.warning (stmt.source_reference, "`null' incompatible with return type `%s`".printf (current_return_type.to_string ()));
 		}
 
-		if (stmt.return_expression != null) {
-			stmt.add_error_types (stmt.return_expression.get_error_types ());
-		}
+		stmt.add_error_types (stmt.return_expression.get_error_types ());
 	}
 
 	public override void visit_throw_statement (ThrowStatement stmt) {



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