digitalmars.D.learn - unittest compiles w/o error though module file is not named after the
- kdevel (32/32) Feb 06 2021 ```p.d
- Adam D. Ruppe (14/14) Feb 06 2021 Module names and file names are completely independent on the
```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.
Feb 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. 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.
Feb 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").
Feb 06 2021
On 06.02.21 16:05, kdevel wrote:On Saturday, 6 February 2021 at 14:52:57 UTC, Adam D. Ruppe wrote: [...]Looks like <https://issues.dlang.org/show_bug.cgi?id=15086>.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; } ```
Feb 06 2021