diff -r 241d082d6d89 -r 99ab8b19f0b9 src/compiler/NameBinding.cpp --- a/src/compiler/NameBinding.cpp Sat Jan 12 16:13:46 2013 -0800 +++ b/src/compiler/NameBinding.cpp Sat Jan 12 16:26:09 2013 -0800 @@ -887,7 +887,18 @@ } else { Local module(zone_, Module::cast(importable)); if (!module->globals()) - importAllFromTranslationUnit(node, module, module->translationUnit()); + importAllFromTranslationUnit(node, module->translationUnit()); + else + assert(false); + } + } else { + Local importable(zone_, unit_->module()->getImportAt(node->importIndex())); + if (importable->isPackage()) { + assert(false); + } else { + Local module(zone_, Module::cast(importable)); + if (!module->globals()) + importFromTranslationUnit(node, module->translationUnit()); else assert(false); } @@ -895,25 +906,53 @@ } private: - void importAllFromTranslationUnit(ImportStatement *node, Handle module, TranslationUnit *other) { + bool importFrom(ImportStatement *node, Symbol *import) { + assert(import->type()); + + // Check for duplicate import names. + if (unit_->importScope()->localLookup(import->name())) { + cc_.reportError(node->pos(), Message_DuplicateImport, import->name()->chars()); + return false; + } + + ImplicitSymbol *sym = new (pool_) ImplicitSymbol(unit_->importScope(), + import->name(), + node->pos(), + import->type(), + node->importIndex()); + if (!unit_->importScope()->addSymbol(sym)) + return false; + + return true; + } + + void importFromTranslationUnit(ImportStatement *node, TranslationUnit *other) { + assert(!other->failed()); + + for (size_t i = 0; i < node->names()->length(); i++) { + Handle name = *node->names()->at(i); + + // See if the name exists in the other translation unit. + Symbol *import = other->globalScope()->findExported(name); + if (!import) { + FixedArray *path = unit_->module()->importPathAt(node->importIndex()); + cc_.reportError(node->pos(), Message_NotFoundInImportable, + name->chars(), + String::cast(path->at(path->length() - 1))->chars()); + return; + } + + if (!importFrom(node, import)) + return; + } + } + + void importAllFromTranslationUnit(ImportStatement *node, TranslationUnit *other) { assert(!other->failed()); for (size_t i = 0; i < other->globalScope()->exported()->length(); i++) { Symbol *import = other->globalScope()->exported()->at(i); - assert(import->type()); - - // Check for duplicate import names. - if (unit_->importScope()->localLookup(import->name())) { - cc_.reportError(node->pos(), Message_DuplicateImport, import->name()->chars()); - return; - } - - ImplicitSymbol *sym = new (pool_) ImplicitSymbol(unit_->importScope(), - import->name(), - node->pos(), - import->type(), - node->importIndex()); - if (!unit_->importScope()->addSymbol(sym)) + if (!importFrom(node, import)) return; } }