diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-23 11:36:23 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-23 11:36:23 +0800 |
commit | 28b1e61bd288a0e55cc0c6cb2d6c98be6983b0a1 (patch) | |
tree | 866702e46728eaa063dfdf20218dc6dcc5cc4e98 /src/resolve | |
parent | 5bc5d0122bf5f38ef394b9f3363995193c476530 (diff) | |
download | mrust-28b1e61bd288a0e55cc0c6cb2d6c98be6983b0a1.tar.gz |
Resolve - Place struct enum variants in the type namespace, fix serialisation bug
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/index.cpp | 16 | ||||
-rw-r--r-- | src/resolve/use.cpp | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 71da3b4e..c0276695 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -219,7 +219,21 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod) ), (Static , _add_item_value(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide); ), (Function, _add_item_value(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide); ), - (EnumVar , _add_item_value(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide); ) + (EnumVar , + bool is_struct = false; + if( e.enum_ ) { + ASSERT_BUG(sp, e.idx < e.enum_->variants().size(), "Variant out of range for " << i_data.path); + is_struct = e.enum_->variants().at(e.idx).m_data.is_Struct(); + } + else { + ASSERT_BUG(sp, e.idx < e.hir->m_variants.size(), "Variant out of range for " << i_data.path); + is_struct = e.hir->m_variants.at(e.idx).second.is_Struct(); + } + if( is_struct ) + _add_item_type(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide); + else + _add_item_value(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide); + ) ) } }; diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp index b376e21f..0196108f 100644 --- a/src/resolve/use.cpp +++ b/src/resolve/use.cpp @@ -575,6 +575,7 @@ namespace { auto p = e.path; p.m_components.pop_back(); const auto& enm = ec.m_hir->get_typeitem_by_path(span, p, true).as_Enum(); + assert(e.idx < enm.m_variants.size()); return ::AST::PathBinding::make_EnumVar({ nullptr, e.idx, &enm }); } if( e.path.m_components.empty() ) @@ -619,6 +620,7 @@ namespace { auto p = e.path; p.m_components.pop_back(); const auto& enm = ec.m_hir->get_typeitem_by_path(span, p, true).as_Enum(); + assert(e.idx < enm.m_variants.size()); return ::AST::PathBinding::make_EnumVar({ nullptr, e.idx, &enm }); } item_ptr = &ec.m_hir->get_valitem_by_path(span, e.path, true); // ignore_crate_name=true |