On 7/08/2011 23:18, Jonathan M Davis wrote:
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 main

Hmmm. 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
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."

Reply via email to