From 5deed177a5a6fcd7bad86c8dd4f5866f7b578de3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 31 Dec 2016 14:07:45 +0800 Subject: MIR - Fix a bit of invalid MIR --- src/mir/cleanup.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/mir/cleanup.cpp') diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index 8a5ee1dc..f790c78a 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -120,13 +120,33 @@ const ::HIR::Literal* MIR_Cleanup_GetConstant(const Span& sp, const StaticTraitR if( best_impl ) { - out_ty = best_impl->m_constants.find(pe.item)->second.data.m_type.clone(); + const auto& val = best_impl->m_constants.find(pe.item)->second.data; + out_ty = val.m_type.clone(); // TODO: Obtain `out_ty` by monomorphising the type in the trait. - return &best_impl->m_constants.find(pe.item)->second.data.m_value_res; + return &val.m_value_res; } ), (UfcsInherent, + const ::HIR::TypeImpl* best_impl = nullptr; // TODO: Associated constants (inherent) + resolve.m_crate.find_type_impls(*pe.type, [&](const auto& ty)->const auto& { return ty; }, + [&](const auto& impl) { + auto it = impl.m_constants.find(pe.item); + if( it == impl.m_constants.end() ) + return false; + // TODO: Bounds checks. + // TODO: Impl specialisation? + best_impl = &impl; + return it->second.is_specialisable; + }); + if( best_impl ) + { + const auto& val = best_impl->m_constants.find(pe.item)->second.data; + if( monomorphise_type_needed(val.m_type) ) + TODO(sp, "Monomorphise constant type - " << val.m_type << " for " << path); + out_ty = val.m_type.clone(); + return &val.m_value_res; + } ) ) return nullptr; -- cgit v1.2.3