]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix type check for vfunc returning SimpleType structs
authorLuca Bruno <lucabru@src.gnome.org>
Fri, 13 Jan 2012 20:52:56 +0000 (21:52 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Fri, 13 Jan 2012 20:53:57 +0000 (21:53 +0100)
Fixes bug 667890.

codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
tests/Makefile.am
tests/structs/bug667890.vala [new file with mode: 0644]

index 002c79c887a260e58fd184b966797912060f3810..9ff916a42a2b214182781bbdd5e08cbcb05a02c1 100644 (file)
@@ -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));
                                        }
index 982f5cef9f0b65a02f856eb454e8125f68978162..213a08e46d4a28e133e785e730a25e85b55dde0e 100644 (file)
@@ -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");
 
index fa5111e727275e4e68fc4fc9a18ed50a5def5298..39e49ce9ec776a2cf1541cba99e53a41cc2781fe 100644 (file)
@@ -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 (file)
index 0000000..768ab8c
--- /dev/null
@@ -0,0 +1,10 @@
+[SimpleType]
+struct Foo {
+       public int foo;
+}
+
+interface Bar : Object {
+       public abstract Foo bar ();
+}
+
+void main () { }