Skip to content

Commit 2c62ea4

Browse files
committed
Bug fix for corner case using -i
1 parent c8df957 commit 2c62ea4

24 files changed

Lines changed: 62 additions & 3 deletions

src/dmd/dmodule.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import dmd.globals;
3131
import dmd.id;
3232
import dmd.identifier;
3333
import dmd.parse;
34+
import dmd.root.array;
3435
import dmd.root.file;
3536
import dmd.root.filename;
3637
import dmd.root.outbuffer;
@@ -536,6 +537,10 @@ extern (C++) final class Module : Package
536537
}
537538
m = m.parse();
538539

540+
// verify the module name matches the imported module name
541+
if (!packages.equals((m.md is null) ? null : m.md.packages))
542+
m.error(loc, "from file %s must be imported with 'import %s;'", m.srcfile, m.toPrettyChars());
543+
539544
// Call onImport here because if the module is going to be compiled then we
540545
// need to determine it early because it affects semantic analysis. This is
541546
// being done after parsing the module so the full module name can be taken

src/dmd/root/array.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,15 @@ unittest
313313
array[2] = 910;
314314
assert([123, 421, 910, 123, 1, 2, 8, 20, 4, 3] == array.asDArray);
315315
}
316+
317+
bool equals(T)(const(Array!T)* left, const(Array!T)* right)
318+
{
319+
if (left is null || left.dim == 0)
320+
return right is null || right.dim == 0;
321+
if (right is null || left.dim != right.dim)
322+
return false;
323+
foreach (i; 0 .. left.dim)
324+
if ((*left)[i] != (*right)[i])
325+
return false;
326+
return true;
327+
}

test/fail_compilation/badimport.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// COMPILED_IMPORTS: imports/nomodname.d
2+
// REQUIRED_ARGS: -Ifail_compilation
3+
// PERMUTE_ARGS:
4+
import imports.nomodname;

test/fail_compilation/badimport2.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// COMPILED_IMPORTS: imports/incompletemodname.d
2+
// REQUIRED_ARGS: -Ifail_compilation
3+
// PERMUTE_ARGS:
4+
import imports.incompletemodname;

test/fail_compilation/badimport3.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// COMPILED_IMPORTS: imports/incompletemodname.d
2+
// REQUIRED_ARGS: -Ifail_compilation
3+
// PERMUTE_ARGS:
4+
import imports.wrongpkgname;

test/fail_compilation/ice11919.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
TEST_OUTPUT:
33
---
44
fail_compilation/ice11919.d(17): Error: cannot interpret `foo` at compile time
5-
fail_compilation/imports/a11919.d(4): Error: template instance a11919.doBar!(Foo).doBar.zoo!(t) error instantiating
6-
fail_compilation/imports/a11919.d(11): instantiated from here: `doBar!(Foo)`
5+
fail_compilation/imports/a11919.d(5): Error: template instance imports.a11919.doBar!(Foo).doBar.zoo!(t) error instantiating
6+
fail_compilation/imports/a11919.d(12): instantiated from here: `doBar!(Foo)`
77
fail_compilation/ice11919.d(25): instantiated from here: `doBar!(Bar)`
88
---
99
*/

test/fail_compilation/imports/a11919.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module imports.a11919;
12
void doBar(T)(T t)
23
{
34
static if (t.tupleof.length)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// The point of this module is that it should be called imports.incompletemodname
2+
// but it omits the "imports" in it's name.
3+
module incompletemodname;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// the point of this module is that it has no module name
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module wrongpkg.wrongpkgname;

0 commit comments

Comments
 (0)