[vala] codegen: Fix type check for vfunc returning SimpleType structs



commit d25a600649a4a2bf1487ab04ac5ae38a2d6d9b33
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Jan 13 21:52:56 2012 +0100

    codegen: Fix type check for vfunc returning SimpleType structs
    
    Fixes bug 667890.

 codegen/valaccodebasemodule.vala   |    2 --
 codegen/valaccodemethodmodule.vala |    7 +++++++
 tests/Makefile.am                  |    1 +
 tests/structs/bug667890.vala       |   10 ++++++++++
 4 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 002c79c..9ff916a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2010,8 +2010,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 						param_type.value_owned = !no_implicit_copy (param_type);
 					}
 
-					bool is_unowned_delegate = acc.value_parameter.variable_type is DelegateType && !acc.value_parameter.variable_type.value_owned;
-
 					if (requires_destroy (param_type)) {
 						ccode.add_expression (destroy_parameter (acc.value_parameter));
 					}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 982f5ce..213a08e 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -916,6 +916,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 		push_function (vfunc);
 
+		if (context.assert && m.return_type.data_type is Struct && ((Struct) m.return_type.data_type).is_simple_type () && default_value_for_type (m.return_type, false) == null) {
+			// the type check will use the result variable
+			var vardecl = new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true));
+			vardecl.init0 = true;
+			ccode.add_declaration (get_ccode_name (m.return_type), vardecl);
+		}
+
 		// add a typecheck statement for "self"
 		create_method_type_check_statement (m, return_type, (TypeSymbol) m.parent_symbol, true, "self");
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa5111e..39e49ce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,6 +81,7 @@ TESTS = \
 	structs/bug658048.vala \
 	structs/bug660426.vala \
 	structs/bug661945.vala \
+	structs/bug667890.vala \
 	delegates/delegates.vala \
 	delegates/bug539166.vala \
 	delegates/bug595610.vala \
diff --git a/tests/structs/bug667890.vala b/tests/structs/bug667890.vala
new file mode 100644
index 0000000..768ab8c
--- /dev/null
+++ b/tests/structs/bug667890.vala
@@ -0,0 +1,10 @@
+[SimpleType]
+struct Foo {
+	public int foo;
+}
+
+interface Bar : Object {
+	public abstract Foo bar ();
+}
+
+void main () { }



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