On Thursday, 5 October 2017 at 12:25:27 UTC, Mike Parker wrote:


And actually, now that I think about it, this is probably one of those situations where the defualt fails. So yes, you'll need a module name.

Right. I had to go back and look at what I wrote in Learning D, which is the last (and only) time I played around with the default module behavior. I always use module statements (and you should too).

When you import dir.sub and the compiler finds it's missing in its imported module list, it will look in for the `dir/sub.d` from the current working directory. If it doesn't find it, you get an import error. If you do this:

dmd main.d ../dir/sub.d

Then sub.d can have any module statement you want -- you could do this:

module this.is.the.sub.module;

And it wouldn't matter, as long as main.d imported this.is.the.sub.module and not dir.sub. However, if sub.d has no module statement, the compiler isn't going to infer a package. It's going to be in the default package, so it's simply `sub` and not `dir.sub`. If you import dir.sub, the compiler will still look for a subdirectory named `dir`, but it won't find it.

This latter bit is your issue. dub is passing dir/sub.d to the compiler, but without a module statement the compiler treats it simply as `sub` and your `dir.sub` import fails.
  • Imports Jiyan via Digitalmars-d-learn
    • Re: Imports Mike Parker via Digitalmars-d-learn
      • Re: Imports Jiyan via Digitalmars-d-learn
        • Re: Imports Mike Parker via Digitalmars-d-learn
          • Re: Imports Mike Parker via Digitalmars-d-learn
            • Re: Imports Mike Parker via Digitalmars-d-learn
              • Re: Imports Mike Parker via Digitalmars-d-learn

Reply via email to