[Vala] enum access modifiers



The Vala manual states that an enum takes an access modifier, from 
https://wiki.gnome.org/Projects/Vala/Manual/Enumerated%20types%20%28Enums%29 :"enum-declaration:
 [ access-modifier ] enum qualified-enum-name { [ enum-members ] }"
The following compiles and runs with Vala 0.26.0.33:

void main(){
        var aa = new test();
        print( aa.a.TEST.to_string ());
        }

class test: Object {
        private enum a {
                TEST
                }
        }

and only gives a compilation warning about static members:"private_enum.vala:3.9-3.12: warning: Access to 
static member `test.a' with an instance reference
    print( aa.a.TEST.to_string ());"
So it would appear the current implementation for enums is that they are public and static. So is this an 
implementation bug because the access modifier is ignored or a documentation bug because access modifiers for 
enums aren't that useful?
What has brought this on is a patch adding the 'protected' access modifier to the Genie parser - 
https://bugzilla.gnome.org/show_bug.cgi?id=690848 Generally I would say the 'public', 'private' and 
'protected' access modifiers allow a public interface for using and extending a class to be defined a bit 
more clearly. So implementation details can be hidden with 'private', but also allowed to be extended with 
'protected'. While 'public' provides the accessible API. In that sense enum, as well as struct and delegate, 
can be implementation details where access can be restricted. Enum, struct and delegate are all type 
definitions so probably should not be modifiable by a class sub-type, but readable so they can be accessed 
for creating a variable of the right type. The patch has also highlighted that 'interface' has an access 
modifier. Surely an interface should always be public? Although a method within an interface could possibly 
be protected as a mixin for implementation only?
Any thoughts?
Al Thomas




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]