]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report an error when parsing non-public struct fields
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 11 Aug 2014 12:32:23 +0000 (14:32 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 11 Aug 2014 12:39:51 +0000 (14:39 +0200)
Fixes bug 683413

tests/structs/structs.vala
vala/valaparser.vala
vala/valastruct.vala

index 543975acae7f031bc7e215d074ded1982fa78240..e991121cd7392e7c29c04f9e37d0717a52e28096 100644 (file)
@@ -9,15 +9,6 @@ public struct PublicStruct {
        public int field;
 }
 
-struct StructWithPrivateField {
-       private int field;
-
-       public void test () {
-               field = 1;
-               stdout.printf ("StructWithPrivateField: field = %d\n", field);
-       }
-}
-
 struct StructWithCreationMethod {
        public StructWithCreationMethod () {
                stdout.printf ("StructWithCreationMethod\n");
@@ -78,9 +69,6 @@ void main () {
        test_out_parameter (out simple_struct);
        stdout.printf ("after test_out_parameter: st.field = %d\n", simple_struct.field);
 
-       var struct_with_private_field = StructWithPrivateField ();
-       struct_with_private_field.test ();
-
        stdout.printf (".\n");
 }
 
index c465a8e623c6b56906ce01a9ac161929c19e3daa..89218ebdc02ec9850a9887a2ae8f43032a8355c0 100644 (file)
@@ -2565,7 +2565,7 @@ public class Vala.Parser : CodeVisitor {
 
        void parse_field_declaration (Symbol parent, List<Attribute>? attrs) throws ParseError {
                var begin = get_location ();
-               var access = parse_access_modifier ();
+               var access = parse_access_modifier ((parent is Struct) ? SymbolAccessibility.PUBLIC : SymbolAccessibility.PRIVATE);
                var flags = parse_member_declaration_modifiers ();
                var type = parse_type (true, true);
                string id = parse_identifier ();
@@ -2573,6 +2573,11 @@ public class Vala.Parser : CodeVisitor {
 
                var f = new Field (id, type, null, get_src (begin), comment);
                f.access = access;
+
+               if (parent is Struct && f.access != SymbolAccessibility.PUBLIC) {
+                       Report.error (f.source_reference, "accessibility of struct fields can only be `public`");
+               }
+
                set_attributes (f, attrs);
                if (ModifierFlags.STATIC in flags) {
                        f.binding = MemberBinding.STATIC;
index b9229e0996f93f73b5712712d77384ac381b6b8a..dbbf62992afd93d1ca2089c949bd2f328c1d9bae 100644 (file)
@@ -170,7 +170,6 @@ public class Vala.Struct : TypeSymbol {
         * @param f a field
         */
        public override void add_field (Field f) {
-               // TODO report error when `private' or `protected' has been specified
                f.access = SymbolAccessibility.PUBLIC;
 
                fields.add (f);