From: Rico Tzschichholz Date: Thu, 29 Nov 2018 10:09:51 +0000 (+0100) Subject: vala: Admit that structs are emtpy even with a static property X-Git-Tag: 0.43.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f69ce199190b4579351b82ff2de585da8337dc72;p=thirdparty%2Fvala.git vala: Admit that structs are emtpy even with a static property See https://gitlab.gnome.org/GNOME/vala/issues/446 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 34614c934..6a85be967 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/objects/property-static.vala b/tests/objects/property-static.vala index b5596bd6b..e22448108 100644 --- a/tests/objects/property-static.vala +++ b/tests/objects/property-static.vala @@ -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 index 000000000..3a1270748 --- /dev/null +++ b/tests/structs/struct-empty-still.test @@ -0,0 +1,8 @@ +Invalid Code + +struct Foo { + public static int bar { get; set; } +} + +void main () { +} diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 4c6f59bcc..ca187b56c 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -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;