Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #822 from donc/moduleAndPackageSameName

Bug 176. Error message "module and package have the same name"
  • Loading branch information...
commit 82d5734ae09fec1a98edaf69ea731ebef905a9a8 2 parents b0b0a8c + b4803b2
Walter Bright WalterBright authored
Showing with 16 additions and 10 deletions.
  1. +12 −2 src/import.c
  2. +4 −8 src/module.c
14 src/import.c
View
@@ -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)
{
@@ -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
}
12 src/module.c
View
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.