summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/ast.hpp2
-rw-r--r--src/expand/mod.cpp8
-rw-r--r--src/resolve/index.cpp26
3 files changed, 25 insertions, 11 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index d06f0531..0b2f6729 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -525,7 +525,7 @@ public:
}
bool is_anon() const {
- return m_my_path.nodes().back().name()[0] == '#';
+ return m_my_path.nodes().size() > 0 && m_my_path.nodes().back().name()[0] == '#';
}
/// Create an anon module (for use inside expressions)
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index ee4ea0d4..7292eaa5 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -681,8 +681,12 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST::
for( const auto& mi: mod.macro_imports_res() )
DEBUG("- Imports '" << mi.name << "'");
- if( mod.m_insert_prelude && crate.m_prelude_path != AST::Path() ) {
- mod.add_alias(false, ::AST::UseStmt(Span(), crate.m_prelude_path), "", {});
+ // Insert prelude if: Enabled for this module, present for the crate, and this module is not an anon
+ if( crate.m_prelude_path != AST::Path() )
+ {
+ if( mod.m_insert_prelude && ! mod.is_anon() ) {
+ mod.add_alias(false, ::AST::UseStmt(Span(), crate.m_prelude_path), "", {});
+ }
}
// TODO: Have the AST representation of a module include the definition order,
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() )
{