digitalmars.D.bugs - BUG: Private declaration in module not private
- "Garett Bass" <garettbass studiotekne.com> Nov 07 2005
- "Garett Bass" <garettbass studiotekne.com> Nov 07 2005
- Tomás Rossi <Tomás_member pathlink.com> Nov 08 2005
- "Regan Heath" <regan netwin.co.nz> Nov 08 2005
- Tomás Rossi <Tomás_member pathlink.com> Nov 08 2005
- Derek Parnell <derek psych.ward> Nov 08 2005
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak invalid_utu.fi> Nov 09 2005
When I declare a private function in one module, it remains explicitly
accessible in another module:
------------
module test;
private import std.stdio;
private void foo() { writefln("private test.foo()"); }
private class Bar {
int i;
this() { writefln("new private Bar object"); }
}
------------
module main; // main.d
import test;
int main(char[][] args) {
//foo(); // Error: "module main test.foo is private"
test.foo(); // Bug: "private test.foo()"
Bar bar = new Bar; // Bug: "new private Bar object"
return 0;
}
------------
I think this behavior is incorrect, or at least confusing. I expect private
declarations in modules to be accessible only within
the module. In Java, at least, private class Bar would be inaccessible within
module main.
Regards,
Garett
Nov 07 2005
Btw, I found this is behavior in v.0.137 and v.0.138. "Garett Bass" <garettbass studiotekne.com> wrote in message news:dkoq37$vh1$1 digitaldaemon.com...When I declare a private function in one module, it remains explicitly accessible in another module: ------------ module test; private import std.stdio; private void foo() { writefln("private test.foo()"); } private class Bar { int i; this() { writefln("new private Bar object"); } } ------------ module main; // main.d import test; int main(char[][] args) { //foo(); // Error: "module main test.foo is private" test.foo(); // Bug: "private test.foo()" Bar bar = new Bar; // Bug: "new private Bar object" return 0; } ------------ I think this behavior is incorrect, or at least confusing. I expect private declarations in modules to be accessible only within the module. In Java, at least, private class Bar would be inaccessible within module main. Regards, Garett
Nov 07 2005
In article <dkoq37$vh1$1 digitaldaemon.com>, Garett Bass says...When I declare a private function in one module, it remains explicitly accessible in another module: ------------ module test; private import std.stdio; private void foo() { writefln("private test.foo()"); } private class Bar { int i; this() { writefln("new private Bar object"); } } ------------ module main; // main.d import test; int main(char[][] args) { //foo(); // Error: "module main test.foo is private" test.foo(); // Bug: "private test.foo()" Bar bar = new Bar; // Bug: "new private Bar object" return 0; } ------------ I think this behavior is incorrect, or at least confusing. I expect private declarations in modules to be accessible only within the module. In Java, at least, private class Bar would be inaccessible within module main. Regards, Garett
This simple example also breaks the private rules! console_main.d: --------------- class X { private int a=9; } int main(char[][] args) { X x = new X(); int b = x.a; // No one's complaining here! return 0; } Tom
Nov 08 2005
On Wed, 9 Nov 2005 00:36:32 +0000 (UTC), Tomás Rossi <Tomás_member pathlink.com> wrote:In article <dkoq37$vh1$1 digitaldaemon.com>, Garett Bass says...When I declare a private function in one module, it remains explicitly accessible in another module: ------------ module test; private import std.stdio; private void foo() { writefln("private test.foo()"); } private class Bar { int i; this() { writefln("new private Bar object"); } } ------------ module main; // main.d import test; int main(char[][] args) { //foo(); // Error: "module main test.foo is private" test.foo(); // Bug: "private test.foo()" Bar bar = new Bar; // Bug: "new private Bar object" return 0; } ------------ I think this behavior is incorrect, or at least confusing. I expect private declarations in modules to be accessible only within the module. In Java, at least, private class Bar would be inaccessible within module main. Regards, Garett
This simple example also breaks the private rules! console_main.d: --------------- class X { private int a=9; } int main(char[][] args) { X x = new X(); int b = x.a; // No one's complaining here! return 0; }
If class X and main are in the same module then this is not a bug, see: http://www.digitalmars.com/d/attribute.html "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class." Note: "in the same module" Regan
Nov 08 2005
In article <opszx9pjbk23k2f5 nrage.netwin.co.nz>, Regan Heath says...On Wed, 9 Nov 2005 00:36:32 +0000 (UTC), Tomás Rossi <Tomás_member pathlink.com> wrote:In article <dkoq37$vh1$1 digitaldaemon.com>, Garett Bass says...When I declare a private function in one module, it remains explicitly accessible in another module: ------------ module test; private import std.stdio; private void foo() { writefln("private test.foo()"); } private class Bar { int i; this() { writefln("new private Bar object"); } } ------------ module main; // main.d import test; int main(char[][] args) { //foo(); // Error: "module main test.foo is private" test.foo(); // Bug: "private test.foo()" Bar bar = new Bar; // Bug: "new private Bar object" return 0; } ------------ I think this behavior is incorrect, or at least confusing. I expect private declarations in modules to be accessible only within the module. In Java, at least, private class Bar would be inaccessible within module main. Regards, Garett
This simple example also breaks the private rules! console_main.d: --------------- class X { private int a=9; } int main(char[][] args) { X x = new X(); int b = x.a; // No one's complaining here! return 0; }
If class X and main are in the same module then this is not a bug, see: http://www.digitalmars.com/d/attribute.html
Sorry i miss that one... it's just that this rule doesn't seems to be so natural for a C++ programmer. It's really confusing and in fact, now that you bring it to the table, it's ugly and useless."Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class." Note: "in the same module" Regan
Regards Tom
Nov 08 2005
On Wed, 9 Nov 2005 03:32:01 +0000 (UTC), Tomás Rossi wrote:If class X and main are in the same module then this is not a bug, see: http://www.digitalmars.com/d/attribute.html
Sorry i miss that one... it's just that this rule doesn't seems to be so natural for a C++ programmer. It's really confusing and in fact, now that you bring it to the table, it's ugly and useless.
I think it is there to deal with the C++ 'friend' concept. Class that are friendly to each other are supposed to be coded into the same module (a.k.a. source file). -- Derek (skype: derek.j.parnell) Melbourne, Australia 9/11/2005 2:44:28 PM
Nov 08 2005
Garett Bass wrote:When I declare a private function in one module, it remains explicitly accessible in another module: ------------ module test; private import std.stdio; private void foo() { writefln("private test.foo()"); } private class Bar { int i; this() { writefln("new private Bar object"); } } ------------ module main; // main.d import test; int main(char[][] args) { //foo(); // Error: "module main test.foo is private" test.foo(); // Bug: "private test.foo()" Bar bar = new Bar; // Bug: "new private Bar object" return 0; } ------------ I think this behavior is incorrect, or at least confusing. I expect private declarations in modules to be accessible only within the module. In Java, at least, private class Bar would be inaccessible within module main.
From http://www.digitalmars.com/d/attribute.html: "Static does not have the additional C meaning of being local to a file. Use the private attribute in D to achieve that. For example: module foo; int x = 3; // x is global private int y = 4; // y is local to module foo
Nov 09 2005









"Garett Bass" <garettbass studiotekne.com> 