digitalmars.D - Does the 'package' protection attribute not work?
- Stijn Herreman (15/15) Aug 07 2011 module main;
- Jonathan M Davis (12/35) Aug 07 2011 Hmmm. My guess would be that either it's a bug or that from D's perspect...
- Stijn Herreman (9/44) Aug 07 2011 The actual code does make use of a package hierarchy. At least, I'm
- Jonathan M Davis (7/61) Aug 07 2011 TDPL is correct with regards to how packages are _supposed_ to work. Whe...
- Robert Clipsham (10/16) Aug 07 2011 Except package is ~100% useless if you use an *actual* package
- Jonathan M Davis (5/21) Aug 07 2011 Ah. Then package is horribly broken at the moment. Lovely. I guess that ...
- Robert Clipsham (7/10) Aug 08 2011 Another possibility is it's not used because it doesn't work - that's my...
- Jacob Carlborg (4/20) Aug 07 2011 In addition to that a method declared as "package" won't be virtual.
- Andrei Alexandrescu (3/26) Aug 08 2011 Ouch. Why is that? Seems like a bug.
- Jacob Carlborg (11/38) Aug 08 2011 Note, this is nothing new, it's been like this for ages. I don't know if...
- Michel Fortin (20/47) Aug 08 2011 Seems by design. See dmd/src/func.c :
- Jacob Carlborg (5/40) Aug 07 2011 Or because neither of the modules are in package they are perhaps in an
- Jonathan M Davis (7/54) Aug 08 2011 Except that I don't think that sub-packages have access to the package
- Jacob Carlborg (5/14) Aug 08 2011 No, sub-packages don't have access to the parent package. Hence the "in
module main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from main
Aug 07 2011
On Sunday 07 August 2011 18:58:53 Stijn Herreman wrote:module main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from mainHmmm. My guess would be that either it's a bug or that from D's perspective, neither of your modules are in a package. They have no package in front of their names; they're at the base level of the hierarchy. And that might mean that they don't have a package, so they don't share a package. But I don't know. Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though. - Jonathan M Davis
Aug 07 2011
On 7/08/2011 23:18, Jonathan M Davis wrote:On Sunday 07 August 2011 18:58:53 Stijn Herreman wrote:The actual code does make use of a package hierarchy. At least, I'm under the impression it does: the files are in a subdirectory. Explicitly stating the package and module name in the files make the 'package' attribute work. So either the attribute does not work when the package and module name aren't explicitly stated, or a directory does not equal a package. From "The D Programming Language": "we refer to [...] a directory containing D source files as a package."module main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from mainHmmm. My guess would be that either it's a bug or that from D's perspective, neither of your modules are in a package. They have no package in front of their names; they're at the base level of the hierarchy. And that might mean that they don't have a package, so they don't share a package. But I don't know. Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though. - Jonathan M Davis
Aug 07 2011
On Monday 08 August 2011 00:19:56 Stijn Herreman wrote:On 7/08/2011 23:18, Jonathan M Davis wrote:TDPL is correct with regards to how packages are _supposed_ to work. Whether they _actually_ work that way at the moment, I don't know. I've rarely had use for them, so I'm not sure that I've ever actually tried it. There's every possibility that package is currently broken. But what you've read in TDPL is definitely how packages are supposed to work. - Jonathan M DavisOn Sunday 07 August 2011 18:58:53 Stijn Herreman wrote:The actual code does make use of a package hierarchy. At least, I'm under the impression it does: the files are in a subdirectory. Explicitly stating the package and module name in the files make the 'package' attribute work. So either the attribute does not work when the package and module name aren't explicitly stated, or a directory does not equal a package. From "The D Programming Language": "we refer to [...] a directory containing D source files as a package."module main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from mainHmmm. My guess would be that either it's a bug or that from D's perspective, neither of your modules are in a package. They have no package in front of their names; they're at the base level of the hierarchy. And that might mean that they don't have a package, so they don't share a package. But I don't know. Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though. - Jonathan M Davis
Aug 07 2011
On 07/08/2011 22:18, Jonathan M Davis wrote:Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package -- Robert http://octarineparrot.com/
Aug 07 2011
On Sunday 07 August 2011 23:29:26 Robert Clipsham wrote:On 07/08/2011 22:18, Jonathan M Davis wrote:Ah. Then package is horribly broken at the moment. Lovely. I guess that that just goes to show that it's not used heavily or there would be a lot more complaints about it. - Jonathan M DavisPersonally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package
Aug 07 2011
On 08/08/2011 02:10, Jonathan M Davis wrote:Ah. Then package is horribly broken at the moment. Lovely. I guess that that just goes to show that it's not used heavily or there would be a lot more complaints about it.Another possibility is it's not used because it doesn't work - that's my current situation, and I don't bother complaining about it as these problems have been known since long before D1.0 was released, let alone D2. -- Robert http://octarineparrot.com/
Aug 08 2011
On 2011-08-08 00:29, Robert Clipsham wrote:On 07/08/2011 22:18, Jonathan M Davis wrote:In addition to that a method declared as "package" won't be virtual. -- /Jacob CarlborgPersonally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package
Aug 07 2011
On 8/8/11 1:56 AM, Jacob Carlborg wrote:On 2011-08-08 00:29, Robert Clipsham wrote:Ouch. Why is that? Seems like a bug. AndreiOn 07/08/2011 22:18, Jonathan M Davis wrote:In addition to that a method declared as "package" won't be virtual.Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package
Aug 08 2011
On 2011-08-08 15:55, Andrei Alexandrescu wrote:On 8/8/11 1:56 AM, Jacob Carlborg wrote:Note, this is nothing new, it's been like this for ages. I don't know if it's by design or if it's a bug. The specification says: "All non-static non-private non-template member functions are virtual.", which would indicate that methods declared as "package" are virtual as well, but that has never been the case. This is the only issue I can find about it, but I'm quite sure it existed long before that: http://d.puremagic.com/issues/show_bug.cgi?id=3258 http://www.d-programming-language.org/function.html -- /Jacob CarlborgOn 2011-08-08 00:29, Robert Clipsham wrote:Ouch. Why is that? Seems like a bug. AndreiOn 07/08/2011 22:18, Jonathan M Davis wrote:In addition to that a method declared as "package" won't be virtual.Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package
Aug 08 2011
On 2011-08-08 13:55:32 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:On 8/8/11 1:56 AM, Jacob Carlborg wrote:Seems by design. See dmd/src/func.c : int FuncDeclaration::isVirtual() { #if 0 … #endif Dsymbol *p = toParent(); return isMember() && !(isStatic() || protection == PROTprivate || protection == PROTpackage) && p->isClassDeclaration() && !(p->isInterfaceDeclaration() && isFinal()); } At least now you know where to fix this. -- Michel Fortin michel.fortin michelf.com http://michelf.com/On 2011-08-08 00:29, Robert Clipsham wrote:Ouch. Why is that? Seems like a bug.On 07/08/2011 22:18, Jonathan M Davis wrote:In addition to that a method declared as "package" won't be virtual.Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though.Except package is ~100% useless if you use an *actual* package hierarchy[1][2][3] (not like phobos which just drops everything in a top-level package).- Jonathan M Davis[1] http://d.puremagic.com/issues/show_bug.cgi?id=143 [2] http://d.puremagic.com/issues/show_bug.cgi?id=2529 [3] http://d.puremagic.com/issues/buglist.cgi?quicksearch=package
Aug 08 2011
On 2011-08-07 23:18, Jonathan M Davis wrote:On Sunday 07 August 2011 18:58:53 Stijn Herreman wrote:Or because neither of the modules are in package they are perhaps in an implicit global package making "package" in this case behave as public. -- /Jacob Carlborgmodule main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from mainHmmm. My guess would be that either it's a bug or that from D's perspective, neither of your modules are in a package. They have no package in front of their names; they're at the base level of the hierarchy. And that might mean that they don't have a package, so they don't share a package. But I don't know. Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though. - Jonathan M Davis
Aug 07 2011
On Monday 08 August 2011 08:55:22 Jacob Carlborg wrote:On 2011-08-07 23:18, Jonathan M Davis wrote:Except that I don't think that sub-packages have access to the package functions in their parent packages, and if that's true, then it's not the same as public. However, if they _do_ have access to their parent packages' package functions, then it _is_ the same as public. I don't think that they do though. But of course, I could be wrong about that. - Jonathan M DavisOn Sunday 07 August 2011 18:58:53 Stijn Herreman wrote:Or because neither of the modules are in package they are perhaps in an implicit global package making "package" in this case behave as public.module main; import std.stdio; import my_module; int main() { my_method(); return 0; } module my_module; import std.stdio; package void my_method() { writeln("Hello D-World!"); } Error: function my_module.my_method is not accessible from mainHmmm. My guess would be that either it's a bug or that from D's perspective, neither of your modules are in a package. They have no package in front of their names; they're at the base level of the hierarchy. And that might mean that they don't have a package, so they don't share a package. But I don't know. Personally, I don't see much point in using the package specifier when you're not actually using a package hierarchy (you're just making it so that everything but stuff which actually uses a hierarchy can use the function - it would be a really weird distinction to make). So, it wouldn't entirely surprise me if this is completely by design. It might be a bug though. - Jonathan M Davis
Aug 08 2011
On 2011-08-08 09:11, Jonathan M Davis wrote:On Monday 08 August 2011 08:55:22 Jacob Carlborg wrote:No, sub-packages don't have access to the parent package. Hence the "in this case". I guess I wasn't very clear. -- /Jacob CarlborgOr because neither of the modules are in package they are perhaps in an implicit global package making "package" in this case behave as public.Except that I don't think that sub-packages have access to the package functions in their parent packages, and if that's true, then it's not the same as public. However, if they _do_ have access to their parent packages' package functions, then it _is_ the same as public. I don't think that they do though. But of course, I could be wrong about that. - Jonathan M Davis
Aug 08 2011