Bug 4242 – ICE(module.c): importing a module with same name as package
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-05-27T15:06:00Z
Last change time
2014-02-15T02:43:11Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2010-05-27T15:06:39Z
Reported by Matthias.
-----
The dmd compiler v2.046 produces correct output ("Error: module test from file xxx.d conflicts with another module test from file yyy.d"), if multiple placement of same module identifier are in the root of the project, however it crashes, when the files are in a subfolder and does not display a proper error message.
The output is:
Assertion failure: 'mprev' on line 641 in file 'module.c'
Test case:
--main.d--
import std.stdio;
import folder.File1;
import folder.File2;
int main(char[][] args)
{
writefln(file2);
return 0;
}
--folder\File1.d--
module folder;
const char[] file1 = "File1";
--folder\File2.d--
module folder;
const char[] file2 = "File2";
Comment #1 by clugdbug — 2010-05-27T22:53:49Z
This is a regression since DMD2.043. Only a single import is required (don't need File2 in the test case).
PATCH:
Index: module.c
===================================================================
--- module.c (revision 502)
+++ module.c (working copy)
@@ -638,9 +638,16 @@
Dsymbol *prev = dst->lookup(ident);
assert(prev);
Module *mprev = prev->isModule();
- assert(mprev);
- error(loc, "from file %s conflicts with another module %s from file %s",
- srcname, mprev->toChars(), mprev->srcfile->toChars());
+ if (mprev)
+ error(loc, "from file %s conflicts with another module %s from file %s",
+ srcname, mprev->toChars(), mprev->srcfile->toChars());
+ else
+ {
+ Package *pkg = prev->isPackage();
+ assert(pkg);
+ error(loc, "from file %s conflicts with package name %s ",
+ srcname, pkg->toChars());
+ }
}
else
{