diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-12 10:59:25 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-12 10:59:25 +0800 |
commit | be5a94e5e1537e91e4ace4ed9694394dcef9f291 (patch) | |
tree | f4e38c8421d473c970397825a2cfb089ed610031 /src/hir/hir.cpp | |
parent | d711bdac7f85a10a346933b4ad4a87fc52c95504 (diff) | |
download | mrust-be5a94e5e1537e91e4ace4ed9694394dcef9f291.tar.gz |
HIR - Fix edge case looking up the root module
Diffstat (limited to 'src/hir/hir.cpp')
-rw-r--r-- | src/hir/hir.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 636ff7a0..16ab94e4 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -409,12 +409,27 @@ const ::HIR::TypeItem& ::HIR::Crate::get_typeitem_by_path(const Span& sp, const const ::HIR::Module& ::HIR::Crate::get_mod_by_path(const Span& sp, const ::HIR::SimplePath& path) const { - const auto& ti = this->get_typeitem_by_path(sp, path); - TU_IFLET(::HIR::TypeItem, ti, Module, e, - return e; - ) - else { - BUG(sp, "Module path " << path << " didn't point to a module"); + if( path.m_components.size() == 0 ) + { + if( path.m_crate_name != "" ) + { + ASSERT_BUG(sp, m_ext_crates.count(path.m_crate_name) > 0, "Crate '" << path.m_crate_name << "' not loaded"); + return m_ext_crates.at(path.m_crate_name)->m_root_module; + } + else + { + return this->m_root_module; + } + } + else + { + const auto& ti = this->get_typeitem_by_path(sp, path); + TU_IFLET(::HIR::TypeItem, ti, Module, e, + return e; + ) + else { + BUG(sp, "Module path " << path << " didn't point to a module"); + } } } const ::HIR::Trait& ::HIR::Crate::get_trait_by_path(const Span& sp, const ::HIR::SimplePath& path) const |