nested module problem
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 2 14:42:59 PDT 2017
On Saturday, 2 September 2017 at 21:24:19 UTC, Jean-Louis Leroy
wrote:
> On Saturday, 2 September 2017 at 20:48:22 UTC, Moritz Maxeiner
> wrote:
>> So the compiler wants you to import it by the name it has
>> inferred for you (The fix being either specifying the module
>> name in foo/bar.d as `module foo.bar`, or importing it as via
>> `import bar;` in foo.d).
>> [1] https://dlang.org/spec/module.html
>
> I thought of doing that, it merely changed the error. OK now I
> have:
>
> in foo.d:
> module foo;
> import foo.bar;
>
> in foo/bar.d:
> module foo.bar;
>
> $ dmd -c foo.d foo/bar.d
> foo/bar.d(1): Error: package name 'foo' conflicts with usage as
> a module name in file foo.d
>
> If I compile separately:
> jll at ORAC:~/dev/d/tests/modules$ dmd -I. -c foo.d
> foo/bar.d(1): Error: package name 'foo' conflicts with usage as
> a module name in file foo.d
Yes, these now both fail because you cannot have a module `foo`
and a package `foo` at the same time (they share a namespace), I
forgot about that.
> jll at ORAC:~/dev/d/tests/modules$ dmd -I. -c foo/bar.d
(same as before, no issue here)
>
> It believes that 'foo' is a package...because there is a 'foo'
> directory?
You created the 'foo' package by specifying `module foo.bar` in
foo/bar.d.
>
> I see that a workaround is to move foo.d to foo/package.d but I
> would like to avoid that.
AFAIK you can't; consider:
-- baz.d ---
import foo;
------------
in the same directory as foo.d. If foo/package.d exists (with
`module foo` inside), what should baz.d import? foo.d or
foo/package.d?
The point being that we could have either used foo/package.d or
foo.d for a package file, but not both (as that would allow
ambiguity) and package.d was chosen.
[1] https://dlang.org/spec/module.html#package-module
More information about the Digitalmars-d-learn
mailing list