diff options
-rw-r--r-- | src/hir_conv/bind.cpp | 16 | ||||
-rw-r--r-- | src/hir_conv/resolve_ufcs.cpp | 60 |
2 files changed, 64 insertions, 12 deletions
diff --git a/src/hir_conv/bind.cpp b/src/hir_conv/bind.cpp index d8df0d3b..93f63abd 100644 --- a/src/hir_conv/bind.cpp +++ b/src/hir_conv/bind.cpp @@ -152,8 +152,7 @@ namespace { bool is_single_value = pat.m_data.is_Value(); TU_IFLET( ::HIR::Pattern::Value, val, Named, ve, - TU_MATCH( ::HIR::Path::Data, (ve.path.m_data), (pe), - (Generic, + TU_IFLET( ::HIR::Path::Data, ve.path.m_data, Generic, pe, const ::HIR::Enum* enm = nullptr; const auto& path = pe.m_path; const ::HIR::Module* mod; @@ -242,17 +241,10 @@ namespace { ) ) } - ), - (UfcsInherent, - TODO(sp, "Pattern value UfcsInherent - " << ve.path); - ), - (UfcsKnown, - TODO(sp, "Pattern value UfcsKnown - " << ve.path); - ), - (UfcsUnknown, - BUG(sp, "Pattern value UfcUnkown - " << ve.path); - ) ) + else { + // NOTE: Defer until Resolve UFCS (saves duplicating logic) + } ) } diff --git a/src/hir_conv/resolve_ufcs.cpp b/src/hir_conv/resolve_ufcs.cpp index 85662a65..9dec8b91 100644 --- a/src/hir_conv/resolve_ufcs.cpp +++ b/src/hir_conv/resolve_ufcs.cpp @@ -409,6 +409,66 @@ namespace { } } + void visit_pattern(::HIR::Pattern& pat) override + { + static Span _sp = Span(); + const Span& sp = _sp; + + ::HIR::Visitor::visit_pattern(pat); + + TU_MATCH_DEF(::HIR::Pattern::Data, (pat.m_data), (e), + ( + ), + (Value, + this->visit_pattern_Value(sp, pat, e.val); + ), + (Range, + this->visit_pattern_Value(sp, pat, e.start); + this->visit_pattern_Value(sp, pat, e.end); + ) + ) + } + void visit_pattern_Value(const Span& sp, const ::HIR::Pattern& pat, ::HIR::Pattern::Value& val) + { + TU_IFLET( ::HIR::Pattern::Value, val, Named, ve, + TRACE_FUNCTION_F(ve.path); + TU_MATCH( ::HIR::Path::Data, (ve.path.m_data), (pe), + (Generic, + // Already done + ), + (UfcsUnknown, + BUG(sp, "UfcsUnknown still in pattern value - " << pat); + ), + (UfcsInherent, + bool rv = m_crate.find_type_impls(*pe.type, [&](const auto& t)->const auto& { return t; }, [&](const auto& impl) { + DEBUG("- matched inherent impl" << impl.m_params.fmt_args() << " " << impl.m_type); + // Search for item in this block + auto it = impl.m_constants.find(pe.item); + if( it != impl.m_constants.end() ) { + ve.binding = &it->second.data; + return true; + } + return false; + }); + if( !rv ) { + ERROR(sp, E0000, "Constant " << ve.path << " couldn't be found"); + } + ), + (UfcsKnown, + bool rv = this->m_resolve.find_impl(sp, pe.trait.m_path, &pe.trait.m_params, *pe.type, [&](const auto& impl) { + if( !impl.m_data.is_TraitImpl() ) { + return true; + } + ve.binding = &impl.m_data.as_TraitImpl().impl->m_constants.at( pe.item ).data; + return true; + }); + if( !rv ) { + ERROR(sp, E0000, "Constant " << ve.path << " couldn't be found"); + } + ) + ) + ) + } const ::HIR::Trait& find_trait(const ::HIR::SimplePath& path) const { |