]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support derived structs with no fields, report an error otherwise
authorLuca Bruno <lethalman88@gmail.com>
Mon, 28 Jun 2010 08:40:46 +0000 (10:40 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 28 Jun 2010 21:42:47 +0000 (23:42 +0200)
Fixes bug 622777.

codegen/valaccodestructmodule.vala
vala/valaclass.vala
vala/valastruct.vala

index d84cbb7a78b0f6136c74287a7fbedd1a13fd5184..4b3587ab345aa716f4f7fbdd86af7cbf6b7102f9 100644 (file)
@@ -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 ()) {
index 54916c592ae12d4588ac3c62f216939688c9fe9a..91fa016c766fdeb9374f02d50433c69155808ebd 100644 (file)
@@ -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;
                                        }
                                }
                        }
index bcfa13e1862a68f0fd3bbcda66d1c369b7fed300..180c67e65d82005916f9af66c7f2c7b87e94daf6 100644 (file)
@@ -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;