digitalmars.D.bugs - BUG: Private declaration in module not private
- Garett Bass (23/23) Nov 07 2005 When I declare a private function in one module, it remains explicitly a...
- Garett Bass (2/26) Nov 07 2005
- Tomás Rossi (12/35) Nov 08 2005 This simple example also breaks the private rules!
- Regan Heath (9/58) Nov 08 2005 If class X and main are in the same module then this is not a bug, see:
- Tomás Rossi (6/69) Nov 08 2005 Sorry i miss that one... it's just that this rule doesn't seems to be so...
- Derek Parnell (9/15) Nov 08 2005 I think it is there to deal with the C++ 'friend' concept. Class that ar...
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (8/40) Nov 09 2005 Yes, this is a real bug (DMD 0.139).
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, GarettThis 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...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" ReganWhen 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, GarettThis 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; }
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: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.In article <dkoq37$vh1$1 digitaldaemon.com>, Garett Bass says...If class X and main are in the same module then this is not a bug, see: http://www.digitalmars.com/d/attribute.htmlWhen 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, GarettThis 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; }"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" ReganRegards Tom
Nov 08 2005
On Wed, 9 Nov 2005 03:32:01 +0000 (UTC), Tomás Rossi wrote: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 PMIf class X and main are in the same module then this is not a bug, see: http://www.digitalmars.com/d/attribute.htmlSorry 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.
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.Yes, this is a real bug (DMD 0.139). 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