Bug 3972 – Regarding module with name different from its file name
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-03-15T15:23:00Z
Last change time
2014-02-15T02:44:19Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-03-15T15:23:57Z
Two modules with file names different from the name used in the module statement:
-------------
// File name: foo.d
module bar;
enum int x = 10;
-------------
// File name: spam.d
module test;
import foo: x;
void main() {}
-------------
When I compile the file spam.d I receive no errors from "spam" being different fom "test". But I (think I) receive an error for "foo" being different from "bar":
spam.d(2): Error: module bar is in multiple packages bar
The compiler can try to give a better/more descriptive error message here.
In this situation if you want the compiler can even give two error messages, complaining that inside the "spam.d" file it has a mismatch module name. If you want to enforce this too, then I think in Tango there are modules that have a name with the first letter upper case, but their file name is all lowercase, so I think the comparison to assert that the module name is the same as the file name is better done caseless (and because in Windows file names are essentially caseless).
Comment #1 by clugdbug — 2010-03-16T13:58:43Z
I actually hit this today and got sufficiently irritated to improve the error message a bit. The 'else' clause should also be improved, it's bug 2059 ("Horrible error message"). Perhaps change it to (untested):
error(loc, "has inconsistent naming. It was imported as %s", srcname);
Index: module.c
===================================================================
--- module.c (revision 416)
+++ module.c (working copy)
@@ -621,7 +621,10 @@
if (!dst->insert(this))
{
if (md)
- error(loc, "is in multiple packages %s", md->toChars());
+ {
+ error(loc, "has inconsistent naming.\n"
+ "It was imported as %s but module declaration is %s", srcname, md->toChars());
+ }
else
error(loc, "is in multiple defined");
}
Comment #2 by bearophile_hugs — 2010-03-17T04:23:03Z
Thank you.
Can the compiler complain in the other situation too? (I mean when no imports are present, and your program is a file named "foo.d" with written "module bar;" at the top?
If the mismatch name is an error when you import the module, then I think it has to be an error in this case too.
Comment #3 by bugzilla — 2010-03-28T17:48:31Z
changeset 427
Comment #4 by bugzilla — 2010-03-28T17:49:55Z
*** Issue 2059 has been marked as a duplicate of this issue. ***
Comment #5 by bearophile_hugs — 2010-04-09T10:39:50Z
In dmd 2.043 now compiling spam.d generates the error:
spam.d(3): Error: module bar from file foo.d conflicts with another module bar from file foo.d
That's not a a good error message, I am not able to understand it.
A better error message is like the following pair:
spam.d(2): Error: module 'test' has mismatched file name 'spam.d'.
foo.d(2): Error: module 'bar' has mismatched file name 'foo.d'.
Note that they are two errors, because both modules have a wrong/mismatched name.
Comment #6 by bearophile_hugs — 2010-04-09T14:53:02Z
After a short discussion with Walter it seems that in D it's OK to have a file named "foo.d" with inside it at the top written "module bar;".
The rationale behind it is "The flexibility comes in handy now and then.".
So probably there's no interest in fixing this small umpteenth hole in the module system.
Comment #7 by andrej.mitrovich — 2012-12-20T15:19:33Z
pull for 4479 will fix this, with the new message being:
spam.d(2): Error: module bar from file foo.d must be imported as module 'bar'
*** This issue has been marked as a duplicate of issue 4479 ***
Comment #8 by bearophile_hugs — 2012-12-20T17:28:34Z