]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Admit that structs are emtpy even with a static property
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 29 Nov 2018 10:09:51 +0000 (11:09 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 29 Nov 2018 13:03:35 +0000 (14:03 +0100)
See https://gitlab.gnome.org/GNOME/vala/issues/446

tests/Makefile.am
tests/objects/property-static.vala
tests/structs/struct-empty-still.test [new file with mode: 0644]
vala/valastruct.vala

index 34614c93476158a34439199ae2d3adefcd0bcf3b..6a85be967527aaac6852d0154ec69952e2245798 100644 (file)
@@ -187,6 +187,7 @@ TESTS = \
        enums/bug763831.vala \
        enums/bug780050.vala \
        structs/struct_only.vala \
+       structs/struct-empty-still.test \
        structs/struct-no-gtype.vala \
        structs/structs.vala \
        structs/gvalue.vala \
index b5596bd6b2b9bf4dc2c3d2b95404460289db9667..e224481089499a63e4925b04cf1b987f6a145678 100644 (file)
@@ -15,6 +15,8 @@ class Foo {
 }
 
 struct Bar {
+       public int foo;
+
        static int _bar;
        static int _baz;
 
diff --git a/tests/structs/struct-empty-still.test b/tests/structs/struct-empty-still.test
new file mode 100644 (file)
index 0000000..3a12707
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+struct Foo {
+       public static int bar { get; set; }
+}
+
+void main () {
+}
index 4c6f59bcc2c24eedabbe61a78946e0990e145d9d..ca187b56c16df648fa42ddfc7d49bfdb69ea4d4e 100644 (file)
@@ -530,18 +530,20 @@ public class Vala.Struct : TypeSymbol {
                }
 
                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;
-                                       }
+                       bool has_instance_field = false;
+                       foreach (Field f in fields) {
+                               if (f.binding == MemberBinding.INSTANCE) {
+                                       has_instance_field = true;
+                                       break;
                                }
                        }
+                       if (base_type == null && !has_instance_field && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) {
+                               error = true;
+                               Report.error (source_reference, "struct `%s' cannot be empty".printf (get_full_name ()));
+                       } else if (base_type != null && has_instance_field) {
+                               error = true;
+                               Report.error (source_reference, "derived struct `%s' may not have instance fields".printf (get_full_name ()));
+                       }
                }
 
                context.analyzer.current_source_file = old_source_file;