From: Luca Bruno Date: Fri, 13 Jan 2012 20:52:56 +0000 (+0100) Subject: codegen: Fix type check for vfunc returning SimpleType structs X-Git-Tag: 0.14.2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=393f45975722ceee5b22698b04df3148511d7845;p=thirdparty%2Fvala.git codegen: Fix type check for vfunc returning SimpleType structs Fixes bug 667890. --- diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index a5be33465..8ef6e6689 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -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"); diff --git a/tests/Makefile.am b/tests/Makefile.am index d4e1af194..8835bff73 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..768ab8c58 --- /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 () { }