Re: [Vala] namespace access-modifier



On Mon, 2013-03-11 at 23:00 +0100, Florian wrote:
Hi! :)

According to this Document one can declare namspace members public or
private:
http://www.vala-project.org/doc/vala-draft/namespaces.html
        "Namespace members can be declared either private or public.
        Public data can be accessed from any code, while private data
        can only be accessed from inside the namespace."

Well, it looks like the documentation simply doesn't match the real
behaviour of valac here. I guess this is a compiler bug, which would
mean filing a report on Bugzilla. I have a more complete example here:

namespace TestNs {
        private int i;
        private void foo() { i = 5; }
}
class Test {
        private int i;
        private static int j;
        private static void bar() { j = 20;}
        private void foo() { i = 10; }
}
int main (string[] args) {
        TestNs.foo();
        TestNs.i = 1;

        Test.bar();
        Test.j = 1;

        var x = new Test();
        x.foo();
        x.i = 1;
}
$ valac -C test2.vala
test2.vala:27.2-27.9: error: Access to private member `Test.bar' denied
        Test.bar();
        ^^^^^^^^
test2.vala:28.2-28.7: error: Access to private member `Test.j' denied
        Test.j = 1;
        ^^^^^^
test2.vala:31.2-31.6: error: Access to private member `Test.foo' denied
        x.foo();
        ^^^^^
test2.vala:32.2-32.4: error: Access to private member `Test.i' denied
        x.i = 1;
        ^^^
Compilation failed: 4 error(s), 0 warning(s)

-- 
Calvin Walton <calvin walton kepstin ca>

Attachment: smime.p7s
Description: S/MIME cryptographic signature



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