Keyword "package" prevents from importing a package module "package.d"

Arafel er.krali at gmail.com
Thu Nov 2 13:15:55 UTC 2023


On 02.11.23 13:52, BoQsc wrote:
> Well the whole thread is about importing `package.d` while being inside 
> package to provide runnable working example which contains debug 
> information of the package.

Sorry, but I have never seen a package that includes examples within the 
package directory itself, nor am I able to imagine why anybody would 
want that. It would just be polluting the package folder with 
unnecessary files.

Examples are usually distributed in a separate directory, usually at the 
highest level of the distributable. As for tests, there are `unittest` 
blocks, and if necessary, they are placed in yet another separate directory.

Anyway, your point is moot, because even if you were able to import 
`package.d`, it would still fail at:

```
public import waffle.testing1;
public import waffle.testing2;
```

and for exactly the same reason: the compiler would look for 
`waffle/testing1.d` and it wouldn't find it withing `waffle/`.

You simply can't expect to do `import waffle.foo` from within `waffle/` 
itself (unless you have another `waffle` folder in it, which is often 
the case).

You always invoke the compiler from the outside the package structure, 
that's also how it works in java.


More information about the Digitalmars-d-learn mailing list