]> 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)
committerJürg Billeter <j@bitron.ch>
Tue, 31 Jan 2012 13:02:29 +0000 (14:02 +0100)
Fixes bug 667890.

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

index a5be3346544fc7e5fe05a20e7934d7af24b33782..8ef6e66899128328d51ba263262a43aac1a6964d 100644 (file)
@@ -912,6 +912,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 d4e1af194ddc523c76574fff2b19cadf7c993a44..8835bff73cef97df61028069bf33cc1fbbd97160 100644 (file)
@@ -76,6 +76,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 () { }