Thread overview
unittest compiles w/o error though module file is not named after the module
Feb 06, 2021
kdevel
Feb 06, 2021
Adam D. Ruppe
Feb 06, 2021
kdevel
Feb 06, 2021
ag0aep6g
February 06, 2021
```p.d
module pp;

void foo ()
{
   import std.stdio: writeln;
   __PRETTY_FUNCTION__.writeln;
}
```
```x.d
import p;
```
```main.d
import x;
unittest {
   import pp: foo; // wrong name is accepted if x is imported
//   import p: foo;
   foo;
}
```

$ dmd -i -unittest -main -run main
void pp.foo()
1 unittests passed

Came across this while doing a comprehensive file renaming in a package.
I usually let me guide thru the codebase by the compile error messages.
However, make test unexpectedly succeeded though I have not yet adapted
all import directives.

Of course I could use git grep for this process but I would prefer that
the compilation would fail in the first place.
February 06, 2021
Module names and file names are completely independent on the language level. You can have a file `whatever.d` with `module foo.bar.totally.different;` and `import foo.bar.totally.different` and it all works as long as you add the whatever.d to the build.

The only reason people recommend they match is that then the file can be found automatically.

dmd program.d whatever.d # works from module names

dmd -i program.d # now it will look for foo/bar/totally/different.d by convention because you didn't list the file.


That one `import p;` is kinda weird, it should probably complain then you imported one thing and got another, but generally the name not matching is no problem at all.
February 06, 2021
On Saturday, 6 February 2021 at 14:52:57 UTC, Adam D. Ruppe wrote:

[...]

> That one `import p;` is kinda weird, it should probably complain then you imported one thing and got another, but generally the name not matching is no problem at all.

```main.d (version 2)
// import x;
unittest {
//   import pp: foo; // wrong name is accepted if x is imported
   import p: foo;
   foo;
}
```

also passes the unittest, same output (void pp.foo()). I am under
the impression that at least this main.d version should fail
because there is no module named "p" (it's named "pp").
February 06, 2021
On 06.02.21 16:05, kdevel wrote:
> On Saturday, 6 February 2021 at 14:52:57 UTC, Adam D. Ruppe wrote:
> 
> [...]
> 
>> That one `import p;` is kinda weird, it should probably complain then you imported one thing and got another, but generally the name not matching is no problem at all.
> 
> ```main.d (version 2)
> // import x;
> unittest {
> //   import pp: foo; // wrong name is accepted if x is imported
>     import p: foo;
>     foo;
> }
> ```

Looks like <https://issues.dlang.org/show_bug.cgi?id=15086>.