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).
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"); }
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.
changeset 427
*** Issue 2059 has been marked as a duplicate of this issue. ***
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.
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.
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 ***
Some discussions here: http://forum.dlang.org/thread/iakfgxjlfzrbxerxpria@forum.dlang.org
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル