Thread overview
[Issue 3972] New: Regarding module with name different from its file name
Mar 16, 2010
Don
Mar 29, 2010
Walter Bright
Mar 29, 2010
Walter Bright
Dec 20, 2012
Andrej Mitrovic
March 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972

           Summary: Regarding module with name different from its file
                    name
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-03-15 15:23:57 PDT ---
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).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-03-16 13:58:43 PDT ---
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");
     }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972



--- Comment #2 from bearophile_hugs@eml.cc 2010-03-17 04:23:03 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2010-03-28 17:48:31 PDT ---
changeset 427

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason.james.house@gmail.com


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2010-03-28 17:49:55 PDT ---
*** Issue 2059 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972



--- Comment #5 from bearophile_hugs@eml.cc 2010-04-09 10:39:50 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3972



--- Comment #6 from bearophile_hugs@eml.cc 2010-04-09 14:53:02 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3972


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
         Resolution|                            |DUPLICATE


--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-20 15:19:33 PST ---
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 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3972



--- Comment #8 from bearophile_hugs@eml.cc 2012-12-20 17:28:34 PST ---
Some discussions here:

http://forum.dlang.org/thread/iakfgxjlfzrbxerxpria@forum.dlang.org

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------