Skip to content

Commit

Permalink
Merge pull request dlang#822 from donc/moduleAndPackageSameName
Browse files Browse the repository at this point in the history
Bug 176. Error message "module and package have the same name"
  • Loading branch information
WalterBright committed Mar 22, 2012
2 parents b0b0a8c + b4803b2 commit 82d5734
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/import.c
Expand Up @@ -93,7 +93,16 @@ void Import::load(Scope *sc)

// See if existing module
DsymbolTable *dst = Package::resolve(packages, NULL, &pkg);

#if TARGET_NET //dot net needs modules and packages with same name
#else
if (pkg && pkg->isModule())
{
::error(loc, "can only import from a module, not from a member of module %s. Did you mean `import %s : %s`?",
pkg->toChars(), pkg->toChars(), id->toChars());
mod = pkg->isModule(); // Error recovery - treat as import of that module
return;
}
#endif
Dsymbol *s = dst->lookup(id);
if (s)
{
Expand All @@ -103,7 +112,8 @@ void Import::load(Scope *sc)
if (s->isModule())
mod = (Module *)s;
else
error("package and module have the same name");
::error(loc, "can only import from a module, not from package %s.%s",
pkg->toChars(), id->toChars());
#endif
}

Expand Down
12 changes: 4 additions & 8 deletions src/module.c
Expand Up @@ -1171,14 +1171,10 @@ DsymbolTable *Package::resolve(Identifiers *packages, Dsymbol **pparent, Package
else
{
assert(p->isPackage());
#if TARGET_NET //dot net needs modules and packages with same name
#else
if (p->isModule())
{ p->error("module and package have the same name");
fatal();
break;
}
#endif
// It might already be a module, not a package, but that needs
// to be checked at a higher level, where a nice error message
// can be generated.
// dot net needs modules and packages with same name
}
parent = p;
dst = ((Package *)p)->symtab;
Expand Down

0 comments on commit 82d5734

Please sign in to comment.