From: Luca Bruno Date: Mon, 28 Jun 2010 08:40:46 +0000 (+0200) Subject: Support derived structs with no fields, report an error otherwise X-Git-Tag: 0.9.3~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf46b34f9e262d29720d7d65191969abc838ba83;p=thirdparty%2Fvala.git Support derived structs with no fields, report an error otherwise Fixes bug 622777. --- diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index d84cbb7a7..4b3587ab3 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -103,9 +103,13 @@ public class Vala.CCodeStructModule : CCodeBaseModule { } } - decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ()))); + if (st.base_struct == null) { + decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ()))); - decl_space.add_type_definition (instance_struct); + decl_space.add_type_definition (instance_struct); + } else { + decl_space.add_type_declaration (new CCodeTypeDefinition (st.base_struct.get_cname (), new CCodeVariableDeclarator (st.get_cname ()))); + } var function = new CCodeFunction (st.get_dup_function (), st.get_cname () + "*"); if (st.is_private_symbol ()) { diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 54916c592..91fa016c7 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -1053,6 +1053,7 @@ public class Vala.Class : ObjectTypeSymbol { if (f.binding == MemberBinding.INSTANCE) { error = true; Report.error (source_reference, "derived compact classes may not have instance fields"); + break; } } } diff --git a/vala/valastruct.vala b/vala/valastruct.vala index bcfa13e18..180c67e65 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -828,10 +828,19 @@ public class Vala.Struct : TypeSymbol { prop.check (analyzer); } - if (!external && !external_package && base_type == null && get_fields ().size == 0 - && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) { - error = true; - Report.error (source_reference, "structs cannot be empty: %s".printf(name)); + if (!external && !external_package) { + if (base_type == null && get_fields ().size == 0 && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) { + error = true; + Report.error (source_reference, "structs cannot be empty: %s".printf(name)); + } else if (base_type != null) { + foreach (Field f in fields) { + if (f.binding == MemberBinding.INSTANCE) { + error = true; + Report.error (source_reference, "derived structs may not have instance fields"); + break; + } + } + } } analyzer.current_source_file = old_source_file;