]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Enums require at least one value otherwise report an error
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 24 Apr 2017 06:44:09 +0000 (08:44 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 24 Apr 2017 06:44:09 +0000 (08:44 +0200)
vala/valaenum.vala
vala/valagirparser.vala

index acb8eb35cc23c85eadfde56ffb3eb315c2b3a969..add510783a8449da2758ab2baa894cd4efcbfb50 100644 (file)
@@ -171,6 +171,12 @@ public class Vala.Enum : TypeSymbol {
                }
                context.analyzer.current_symbol = this;
 
+               if (values.size <= 0) {
+                       Report.error (source_reference, "Enum `%s' requires at least one value".printf (get_full_name ()));
+                       error = true;
+                       return false;
+               }
+
                foreach (EnumValue value in values) {
                        value.check (context);
                }
index 6a30f33a5bf855c019ac8617633d83f1a9ecaaea..9b4c0e8dc5ce11bb97fd9aeafdae3100f04c8a51 100644 (file)
@@ -2293,6 +2293,7 @@ public class Vala.GirParser : CodeVisitor {
                sym.access = SymbolAccessibility.PUBLIC;
 
                string common_prefix = null;
+               bool has_member = false;
 
                next ();
 
@@ -2305,6 +2306,7 @@ public class Vala.GirParser : CodeVisitor {
                        }
 
                        if (reader.name == "member") {
+                               has_member = true;
                                if (error_domain) {
                                        parse_error_member ();
                                        calculate_common_prefix (ref common_prefix, old_current.get_cname ());
@@ -2323,6 +2325,10 @@ public class Vala.GirParser : CodeVisitor {
                        pop_metadata ();
                }
 
+               if (!has_member) {
+                       Report.error (get_current_src (), "%s `%s' has no members".printf (element_name, current.name));
+               }
+
                if (common_prefix != null) {
                        sym.set_attribute_string ("CCode", "cprefix", common_prefix);
                }