diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-28 20:14:11 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-28 20:14:11 +0800 |
commit | 47026f277478ffbadb5daa2d85b4600cbec52c9e (patch) | |
tree | 7850eb7cc3c64d37d3d9a0bdb7b3733d5a030e79 /src/resolve/index.cpp | |
parent | 00b321213756480775a9cf369bbf715c7e546cd0 (diff) | |
download | mrust-47026f277478ffbadb5daa2d85b4600cbec52c9e.tar.gz |
Resolve+Expand - Don't include the prelude in anon modules (they get it via the parent)
Diffstat (limited to 'src/resolve/index.cpp')
-rw-r--r-- | src/resolve/index.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 70129a8d..a9751de3 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -55,23 +55,32 @@ void _add_item(const Span& sp, AST::Module& mod, IndexName location, const ::std auto& list = get_mod_index(mod, location); bool was_import = (ir != mod.path() + name); - if( was_import ) { - DEBUG("### Import " << location << " item " << name << " = " << ir); - } - else { - DEBUG("Add " << location << " item '" << name << "': " << ir); - } - if( false == list.insert(::std::make_pair(name, ::AST::Module::IndexEnt { is_pub, was_import, mv$(ir) } )).second ) + if( list.count(name) > 0 ) { if( error_on_collision ) { ERROR(sp, E0000, "Duplicate definition of name '" << name << "' in " << location << " scope (" << mod.path() << ")"); } + else if( list.at(name).path == ir ) + { + // Ignore, re-import of the same thing + } else { - DEBUG("Name collision in " << mod.path() << " - '" << name << "', ignored"); + DEBUG(location << " name collision - '" << name << "' = " << ir << ", ignored (mod=" << mod.path() << ")"); } } + else + { + if( was_import ) { + DEBUG("### Import " << location << " item " << name << " = " << ir); + } + else { + DEBUG("### Add " << location << " item '" << name << "': " << ir); + } + auto rec = list.insert(::std::make_pair(name, ::AST::Module::IndexEnt { is_pub, was_import, mv$(ir) } )); + assert(rec.second); + } } void _add_item_type(const Span& sp, AST::Module& mod, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true) { @@ -350,6 +359,7 @@ void Resolve_Index_Module_Wildcard(AST::Crate& crate, AST::Module& mod, bool han // DEBUG("- Index pre-populated") // return ; //} + // Glob/wildcard imports for( const auto& i : mod.items() ) { |