[vala] codegen: Fix crash when throwing errors from struct constructors



commit 1c89d7f97152ffcfd4b85c64c7343fadc1b22a64
Author: Jürg Billeter <j bitron ch>
Date:   Thu Oct 21 10:33:29 2010 +0200

    codegen: Fix crash when throwing errors from struct constructors
    
    Fixes bug 618461.

 codegen/valagerrormodule.vala |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index a64b38a..b7b4436 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -102,8 +102,8 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 		// free local variables
 		append_local_free (current_symbol, false);
 
-		if (current_method is CreationMethod) {
-			var cl = current_method.parent_symbol as Class;
+		if (current_method is CreationMethod && current_method.parent_symbol is Class) {
+			var cl = (Class) current_method.parent_symbol;
 			var unref_call = get_unref_expression (new CCodeIdentifier ("self"), new ObjectType (cl), null);
 			ccode.add_expression (unref_call);
 			ccode.add_return (new CCodeConstant ("NULL"));
@@ -136,7 +136,11 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 		ccode.add_expression (cclear);
 
 		if (current_method is CreationMethod) {
-			ccode.add_return (new CCodeConstant ("NULL"));
+			if (current_method.parent_symbol is Struct) {
+				ccode.add_return ();
+			} else {
+				ccode.add_return (new CCodeConstant ("NULL"));
+			}
 		} else if (current_method != null && current_method.coroutine) {
 			ccode.add_return (new CCodeConstant ("FALSE"));
 		} else if (current_return_type != null) {



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